Skip to content

Commit acaa81b

Browse files
- add applet
- fix ums with autoboot enabled - add default reboot
1 parent a901470 commit acaa81b

File tree

10 files changed

+381
-9
lines changed

10 files changed

+381
-9
lines changed

Makefile.applet

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
#---------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#---------------------------------------------------------------------------------
4+
5+
ifeq ($(strip $(DEVKITPRO)),)
6+
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
7+
endif
8+
9+
TOPDIR ?= $(CURDIR)
10+
include $(DEVKITPRO)/libnx/switch_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+
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
19+
#
20+
# NO_ICON: if set to anything, do not use icon.
21+
# NO_NACP: if set to anything, no .nacp file is generated.
22+
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
23+
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
24+
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
25+
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
26+
# ICON is the filename of the icon (.jpg), relative to the project folder.
27+
# If not set, it attempts to use one of the following (in this order):
28+
# - <Project name>.jpg
29+
# - icon.jpg
30+
# - <libnx folder>/default_icon.jpg
31+
#
32+
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
33+
# If not set, it attempts to use one of the following (in this order):
34+
# - <Project name>.json
35+
# - config.json
36+
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
37+
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
38+
# NACP building is skipped as well.
39+
#---------------------------------------------------------------------------------
40+
APP_TITLE := Studious Pancake
41+
APP_VERSION := 0.1.0
42+
43+
TARGET := applet/$(notdir $(CURDIR))
44+
BUILD := build.nro
45+
SOURCES := common applet
46+
INCLUDES := common
47+
48+
#---------------------------------------------------------------------------------
49+
# options for code generation
50+
#---------------------------------------------------------------------------------
51+
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
52+
53+
CFLAGS := -g -Wall -Werror -O2 -ffunction-sections \
54+
$(ARCH) $(DEFINES)
55+
56+
CFLAGS += $(INCLUDE) -D__SWITCH__
57+
58+
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=c++20
59+
60+
ASFLAGS := -g $(ARCH)
61+
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
62+
63+
LIBS := -lnx
64+
65+
#---------------------------------------------------------------------------------
66+
# list of directories containing libraries, this must be the top level containing
67+
# include and lib
68+
#---------------------------------------------------------------------------------
69+
LIBDIRS := $(PORTLIBS) $(LIBNX)
70+
71+
72+
#---------------------------------------------------------------------------------
73+
# no real need to edit anything past this point unless you need to add additional
74+
# rules for different file extensions
75+
#---------------------------------------------------------------------------------
76+
ifneq ($(BUILD),$(notdir $(CURDIR)))
77+
#---------------------------------------------------------------------------------
78+
79+
export OUTPUT := $(CURDIR)/$(TARGET)
80+
export TOPDIR := $(CURDIR)
81+
82+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
83+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
84+
85+
export DEPSDIR := $(CURDIR)/$(BUILD)
86+
87+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
88+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
89+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
90+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
91+
92+
#---------------------------------------------------------------------------------
93+
# use CXX for linking C++ projects, CC for standard C
94+
#---------------------------------------------------------------------------------
95+
ifeq ($(strip $(CPPFILES)),)
96+
#---------------------------------------------------------------------------------
97+
export LD := $(CC)
98+
#---------------------------------------------------------------------------------
99+
else
100+
#---------------------------------------------------------------------------------
101+
export LD := $(CXX)
102+
#---------------------------------------------------------------------------------
103+
endif
104+
#---------------------------------------------------------------------------------
105+
106+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
107+
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
108+
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
109+
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
110+
111+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
112+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
113+
-I$(CURDIR)/$(BUILD)
114+
115+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
116+
117+
ifeq ($(strip $(CONFIG_JSON)),)
118+
jsons := $(wildcard *.json)
119+
ifneq (,$(findstring $(TARGET).json,$(jsons)))
120+
export APP_JSON := $(TOPDIR)/$(TARGET).json
121+
else
122+
ifneq (,$(findstring config.json,$(jsons)))
123+
export APP_JSON := $(TOPDIR)/config.json
124+
endif
125+
endif
126+
else
127+
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
128+
endif
129+
130+
ifeq ($(strip $(ICON)),)
131+
icons := $(wildcard *.jpg)
132+
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
133+
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
134+
else
135+
ifneq (,$(findstring icon.jpg,$(icons)))
136+
export APP_ICON := $(TOPDIR)/icon.jpg
137+
endif
138+
endif
139+
else
140+
export APP_ICON := $(TOPDIR)/$(ICON)
141+
endif
142+
143+
ifeq ($(strip $(NO_ICON)),)
144+
export NROFLAGS += --icon=$(APP_ICON)
145+
endif
146+
147+
ifeq ($(strip $(NO_NACP)),)
148+
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
149+
endif
150+
151+
ifneq ($(APP_TITLEID),)
152+
export NACPFLAGS += --titleid=$(APP_TITLEID)
153+
endif
154+
155+
ifneq ($(ROMFS),)
156+
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
157+
endif
158+
159+
.PHONY: $(BUILD) clean all
160+
161+
#---------------------------------------------------------------------------------
162+
all: $(BUILD)
163+
164+
$(BUILD):
165+
@[ -d $@ ] || mkdir -p $@
166+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.applet
167+
168+
#---------------------------------------------------------------------------------
169+
clean:
170+
@echo clean ...
171+
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
172+
173+
174+
#---------------------------------------------------------------------------------
175+
else
176+
.PHONY: all
177+
178+
DEPENDS := $(OFILES:.o=.d)
179+
180+
#---------------------------------------------------------------------------------
181+
# main targets
182+
#---------------------------------------------------------------------------------
183+
all : $(OUTPUT).nro
184+
185+
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
186+
187+
$(OUTPUT).elf : $(OFILES)
188+
189+
$(OFILES_SRC) : $(HFILES_BIN)
190+
191+
#---------------------------------------------------------------------------------
192+
# you need a rule like this for each extension you use as binary data
193+
#---------------------------------------------------------------------------------
194+
%.bin.o %_bin.h : %.bin
195+
#---------------------------------------------------------------------------------
196+
@echo $(notdir $<)
197+
@$(bin2o)
198+
199+
-include $(DEPENDS)
200+
201+
#---------------------------------------------------------------------------------------
202+
endif
203+
#---------------------------------------------------------------------------------------

Makefile renamed to Makefile.overlay

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ include $(DEVKITPRO)/libnx/switch_rules
4040
APP_TITLE := Studious Pancake
4141
APP_VERSION := 0.1.0
4242

43-
TARGET := $(notdir $(CURDIR))
44-
BUILD := build
45-
SOURCES := source
46-
DATA := data
47-
INCLUDES := include libs/tesla/include
43+
TARGET := overlay/$(notdir $(CURDIR))
44+
BUILD := build.ovl
45+
SOURCES := common overlay
46+
INCLUDES := common libs/tesla/include
4847

4948
NO_ICON := 1
5049

@@ -53,7 +52,7 @@ NO_ICON := 1
5352
#---------------------------------------------------------------------------------
5453
ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
5554

56-
CFLAGS := -g -Wall -O2 -ffunction-sections \
55+
CFLAGS := -g -Wall -Werror -O2 -ffunction-sections \
5756
$(ARCH) $(DEFINES)
5857

5958
CFLAGS += $(INCLUDE) -D__SWITCH__
@@ -167,7 +166,7 @@ all: $(BUILD)
167166

168167
$(BUILD):
169168
@[ -d $@ ] || mkdir -p $@
170-
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
169+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.overlay
171170

172171
#---------------------------------------------------------------------------------
173172
clean:

applet/main.cpp

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#include "hekate.hpp"
2+
3+
#include <cstdio>
4+
#include <cstdlib>
5+
#include <switch.h>
6+
#include <vector>
7+
8+
namespace {
9+
10+
typedef void (*TuiCallback)(void *user);
11+
12+
struct TuiItem {
13+
std::string text;
14+
TuiCallback cb;
15+
void *user;
16+
bool selectable;
17+
};
18+
19+
void ConfigCallback(void *user) {
20+
auto config = reinterpret_cast<Hekate::BootConfig *>(user);
21+
22+
Hekate::RebootToConfig(*config);
23+
}
24+
25+
void UmsCallback(void *user) {
26+
Hekate::RebootToUMS(Hekate::UmsTarget_Sd);
27+
28+
(void)user;
29+
}
30+
31+
}
32+
33+
extern "C" void userAppInit(void) {
34+
splInitialize();
35+
}
36+
37+
extern "C" void userAppExit(void) {
38+
splExit();
39+
}
40+
41+
int main(int argc, char **argv) {
42+
auto config_list = Hekate::LoadBootConfigList();
43+
std::vector<TuiItem> items;
44+
45+
items.reserve(config_list.size() + 3);
46+
47+
items.emplace_back("Configs", nullptr, nullptr, false);
48+
for (auto &entry : config_list)
49+
items.emplace_back(entry.name, ConfigCallback, &entry, true);
50+
51+
items.emplace_back("Miscellaneous", nullptr, nullptr, false);
52+
items.emplace_back("Reboot to UMS", UmsCallback, nullptr, true);
53+
54+
std::size_t index = 0;
55+
56+
for (auto &item : items) {
57+
if (item.selectable)
58+
break;
59+
60+
index++;
61+
}
62+
63+
PrintConsole *console = consoleInit(nullptr);
64+
65+
while (appletMainLoop()) {
66+
{
67+
u64 kDown = 0;
68+
69+
hidScanInput();
70+
71+
for (int controller = 0; controller < 10; controller++)
72+
kDown |= hidKeysDown(static_cast<HidControllerID>(controller));
73+
74+
if ((kDown & (KEY_PLUS | KEY_B | KEY_L)))
75+
break;
76+
77+
if ((kDown & KEY_A)) {
78+
auto &item = items[index];
79+
80+
if (item.selectable && item.cb)
81+
item.cb(item.user);
82+
83+
break;
84+
}
85+
86+
if ((kDown & KEY_MINUS)) {
87+
Hekate::RebootDefault();
88+
}
89+
90+
if ((kDown & KEY_DOWN) && (index + 1) < items.size()) {
91+
for (std::size_t i = index; i < items.size(); i++) {
92+
if (!items[i + 1].selectable)
93+
continue;
94+
95+
index = i + 1;
96+
break;
97+
}
98+
}
99+
100+
if ((kDown & KEY_UP) && index > 0) {
101+
for (std::size_t i = index; i > 0; i--) {
102+
if (!items[i - 1].selectable)
103+
continue;
104+
105+
index = i - 1;
106+
break;
107+
}
108+
}
109+
}
110+
111+
consoleClear();
112+
113+
printf("Studious Pancake\n----------------\n");
114+
115+
for (std::size_t i = 0; i < items.size(); i++) {
116+
auto &item = items[i];
117+
bool selected = (i == index);
118+
119+
if (!item.selectable)
120+
console->flags |= CONSOLE_COLOR_FAINT;
121+
122+
printf("%c %s\n", selected ? '>' : ' ', item.text.c_str());
123+
124+
if (!item.selectable)
125+
console->flags &= ~CONSOLE_COLOR_FAINT;
126+
}
127+
128+
consoleUpdate(nullptr);
129+
}
130+
131+
consoleExit(nullptr);
132+
133+
(void)argc;
134+
(void)argv;
135+
136+
return EXIT_SUCCESS;
137+
}

0 commit comments

Comments
 (0)