From 16ce5f4c7bf3993463b1b3284e915df83e8f4967 Mon Sep 17 00:00:00 2001 From: profi200 Date: Mon, 10 Nov 2014 17:03:41 +0100 Subject: [PATCH 1/6] Added functions for launching other apps/applets --- libctru/include/3ds/services/apt.h | 2 ++ libctru/source/services/apt.c | 36 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index a0bfc87..ad94d01 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -73,4 +73,6 @@ Result APT_GetAppCpuTimeLimit(Handle* handle, u32 *percent); Result APT_CheckNew3DS_Application(Handle* handle, u8 *out);//*Application and *System use APT commands 0x01010000 and 0x01020000. Using APT_CheckNew3DS() is recommended, this determines which of those two funcs to use automatically. When this is first called(this calls aptOpenSession/aptCloseSession internally), this initializes an internal flag, which is then used for the out val for all future calls. Result APT_CheckNew3DS_System(Handle* handle, u8 *out); Result APT_CheckNew3DS(Handle* handle, u8 *out); +Result APT_PrepareToDoAppJump(Handle* handle, u8 flags, u64 programID, u8 mediatype); +Result APT_DoAppJump(Handle* handle, u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0Ptr, u8 *NSbuf1Ptr); diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index 7bd0799..db3b011 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -886,3 +886,39 @@ Result APT_CheckNew3DS(Handle* handle, u8 *out) return ret; } +Result APT_PrepareToDoAppJump(Handle* handle, u8 flags, u64 programID, u8 mediatype) +{ + if(!handle)handle=&aptuHandle; + + u32* cmdbuf=getThreadCommandBuffer(); + cmdbuf[0]=0x310100; //request header code + cmdbuf[1]=flags; + cmdbuf[2]=(u32)programID; + cmdbuf[3]=(u32)(programID>>32); + cmdbuf[4]=mediatype; + + Result ret=0; + if((ret=svcSendSyncRequest(*handle)))return ret; + + return cmdbuf[1]; +} + +Result APT_DoAppJump(Handle* handle, u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0Ptr, u8 *NSbuf1Ptr) +{ + if(!handle)handle=&aptuHandle; + + u32* cmdbuf=getThreadCommandBuffer(); + cmdbuf[0]=0x320084; //request header code + cmdbuf[1]=NSbuf0Size; + cmdbuf[2]=NSbuf1Size; + cmdbuf[3]=(NSbuf0Size<<14)|2; + cmdbuf[4]=(u32)NSbuf0Ptr; + cmdbuf[5]=(NSbuf1Size<<14)|0x802; + cmdbuf[6]=(u32)NSbuf1Ptr; + + Result ret=0; + if((ret=svcSendSyncRequest(*handle)))return ret; + + return cmdbuf[1]; +} + From ffe682941fbc691f048a2c015ff8d7fc14adae8e Mon Sep 17 00:00:00 2001 From: profi200 Date: Mon, 10 Nov 2014 17:34:11 +0100 Subject: [PATCH 2/6] Added example for launching apps/applets --- examples/app_launch/Makefile | 139 ++++++++++++++++++++++++++++++ examples/app_launch/source/main.c | 47 ++++++++++ libctru/build.bat | 12 +++ 3 files changed, 198 insertions(+) create mode 100644 examples/app_launch/Makefile create mode 100644 examples/app_launch/source/main.c create mode 100644 libctru/build.bat diff --git a/examples/app_launch/Makefile b/examples/app_launch/Makefile new file mode 100644 index 0000000..c850c22 --- /dev/null +++ b/examples/app_launch/Makefile @@ -0,0 +1,139 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITARM)),) +$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") +endif + +ifeq ($(strip $(CTRULIB)),) +# THIS IS TEMPORARY - in the future it should be at $(DEVKITPRO)/libctru +$(error "Please set CTRULIB in your environment. export CTRULIB=libctru") +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 +# SPECS is the directory containing the important build and link files +#--------------------------------------------------------------------------------- +export TARGET := $(shell basename $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include + + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv6k -mtune=mpcore + +CFLAGS := -g -Wall -O3 -mword-relocations -save-temps \ + -fomit-frame-pointer -ffast-math \ + $(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,$(TARGET).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))) +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)) \ + $(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) + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).3dsx $(TARGET).elf + + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).3dsx : $(OUTPUT).elf +$(OUTPUT).elf : $(OFILES) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + $(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/examples/app_launch/source/main.c b/examples/app_launch/source/main.c new file mode 100644 index 0000000..1c4dcdc --- /dev/null +++ b/examples/app_launch/source/main.c @@ -0,0 +1,47 @@ +#include +#include +#include <3ds.h> + + + +int main() +{ + srvInit(); + aptInit(); + gfxInit(); + hidInit(NULL); + + + u8 buf0[0x300]; + u8 buf1[0x20]; + + + while(aptMainLoop()) + { + hidScanInput(); + svcSleepThread(100000000LL); + + if(hidKeysDown() & KEY_A) + { + memset(buf0, 0, 0x300); + memset(buf1, 0, 0x20); + + aptOpenSession(); + APT_PrepareToDoAppJump(NULL, 0, 0x0004001000022400LL, 0); // *EUR* camera app + APT_DoAppJump(NULL, 0x300, 0x20, buf0, buf1); + aptCloseSession(); + } + + gfxFlushBuffers(); + gfxSwapBuffers(); + gspWaitForVBlank(); + } + + + hidExit(); + gfxExit(); + aptExit(); + srvExit(); + + return 0; +} diff --git a/libctru/build.bat b/libctru/build.bat new file mode 100644 index 0000000..22cb06b --- /dev/null +++ b/libctru/build.bat @@ -0,0 +1,12 @@ +Setlocal +Pushd "%~dp0" +@echo off + +echo. +echo. +make clean +echo. +echo. +make +echo. +echo. From bcd91a9e814ea39381d435214031b8031f34ef0c Mon Sep 17 00:00:00 2001 From: profi200 Date: Mon, 10 Nov 2014 17:38:50 +0100 Subject: [PATCH 3/6] Oops that should not be included --- libctru/build.bat | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 libctru/build.bat diff --git a/libctru/build.bat b/libctru/build.bat deleted file mode 100644 index 22cb06b..0000000 --- a/libctru/build.bat +++ /dev/null @@ -1,12 +0,0 @@ -Setlocal -Pushd "%~dp0" -@echo off - -echo. -echo. -make clean -echo. -echo. -make -echo. -echo. From 8aee967e53b657d50fedf1f46e6e0b8cc8d87904 Mon Sep 17 00:00:00 2001 From: profi200 Date: Mon, 10 Nov 2014 19:23:15 +0100 Subject: [PATCH 4/6] Forget the README --- examples/app_launch/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/app_launch/README.md diff --git a/examples/app_launch/README.md b/examples/app_launch/README.md new file mode 100644 index 0000000..f3f2c08 --- /dev/null +++ b/examples/app_launch/README.md @@ -0,0 +1,7 @@ +app_launch +======= + +Example for launching other apps/applets with ctrulib. Press the A button to launch the app or applet specified in the source. + +Note: The title ID of the EUR Nintendo 3DS Camera app is hardcoded and you need to change it if your 3DS is not an european one. See here for title IDs: http://3dbrew.org/wiki/Title_list#00040010_-_System_Applications + From b17a53fefc8a16426dfc00879875d2a36777bea3 Mon Sep 17 00:00:00 2001 From: profi200 Date: Mon, 10 Nov 2014 22:30:07 +0100 Subject: [PATCH 5/6] Makefile updated, added another note to the README.md file andremoved the svcSleepThread() call --- examples/app_launch/Makefile | 76 +++++++++++++++++++++++-------- examples/app_launch/README.md | 4 +- examples/app_launch/source/main.c | 1 - 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/examples/app_launch/Makefile b/examples/app_launch/Makefile index c850c22..568eda2 100644 --- a/examples/app_launch/Makefile +++ b/examples/app_launch/Makefile @@ -20,21 +20,29 @@ include $(DEVKITARM)/3ds_rules # 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 -# SPECS is the directory containing the important build and link files +# +# NO_SMDH: if set to anything, no SMDH file is generated. +# 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 #--------------------------------------------------------------------------------- -export TARGET := $(shell basename $(CURDIR)) +TARGET := $(notdir $(CURDIR)) BUILD := build SOURCES := source DATA := data INCLUDES := include - #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore +ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=softfp -CFLAGS := -g -Wall -O3 -mword-relocations -save-temps \ +CFLAGS := -g -Wall -O2 -mword-relocations \ -fomit-frame-pointer -ffast-math \ $(ARCH) @@ -43,8 +51,7 @@ 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,$(TARGET).map +LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) LIBS := -lctru -lm @@ -53,15 +60,15 @@ LIBS := -lctru -lm # 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) @@ -98,42 +105,71 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 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 + .PHONY: $(BUILD) clean all - + #--------------------------------------------------------------------------------- all: $(BUILD) $(BUILD): @[ -d $@ ] || mkdir -p $@ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - + #--------------------------------------------------------------------------------- clean: @echo clean ... - @rm -fr $(BUILD) $(TARGET).3dsx $(TARGET).elf - - + @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf + + #--------------------------------------------------------------------------------- else - + DEPENDS := $(OFILES:.o=.d) - + #--------------------------------------------------------------------------------- # main targets #--------------------------------------------------------------------------------- +ifeq ($(strip $(NO_SMDH)),) +.PHONY: all +all : $(OUTPUT).3dsx $(OUTPUT).smdh +endif $(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).elf : $(OFILES) #--------------------------------------------------------------------------------- -# you need a rule like this for each extension you use as binary data +# you need a rule like this for each extension you use as binary data #--------------------------------------------------------------------------------- %.bin.o : %.bin #--------------------------------------------------------------------------------- @echo $(notdir $<) - $(bin2o) + @$(bin2o) + +# WARNING: This is not the right way to do this! TODO: Do it right! +#--------------------------------------------------------------------------------- +%.vsh.o : %.vsh +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin + @bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@ + @echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h + @echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h + @echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h + @rm ../$(notdir $<).shbin -include $(DEPENDS) - + #--------------------------------------------------------------------------------------- endif #--------------------------------------------------------------------------------------- diff --git a/examples/app_launch/README.md b/examples/app_launch/README.md index f3f2c08..2fa1986 100644 --- a/examples/app_launch/README.md +++ b/examples/app_launch/README.md @@ -3,5 +3,7 @@ app_launch Example for launching other apps/applets with ctrulib. Press the A button to launch the app or applet specified in the source. -Note: The title ID of the EUR Nintendo 3DS Camera app is hardcoded and you need to change it if your 3DS is not an european one. See here for title IDs: http://3dbrew.org/wiki/Title_list#00040010_-_System_Applications + +Note: The title ID of the EUR Nintendo 3DS Camera app is hardcoded and you need to change it if your 3DS is not an european one. See here for title IDs: http://3dbrew.org/wiki/Title_list#00040010_-_System_Applications +This example only works if launched as regular app by the home menu. It will not work with the homebrew menu. diff --git a/examples/app_launch/source/main.c b/examples/app_launch/source/main.c index 1c4dcdc..0077c6c 100644 --- a/examples/app_launch/source/main.c +++ b/examples/app_launch/source/main.c @@ -19,7 +19,6 @@ int main() while(aptMainLoop()) { hidScanInput(); - svcSleepThread(100000000LL); if(hidKeysDown() & KEY_A) { From aa2b5d146418cd874e83daa0be4ba7e78dcdaf28 Mon Sep 17 00:00:00 2001 From: profi200 Date: Tue, 11 Nov 2014 15:07:23 +0100 Subject: [PATCH 6/6] Little fix --- libctru/include/3ds/gfx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libctru/include/3ds/gfx.h b/libctru/include/3ds/gfx.h index 83944d7..7953ca6 100644 --- a/libctru/include/3ds/gfx.h +++ b/libctru/include/3ds/gfx.h @@ -29,6 +29,6 @@ u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* hei //global variables extern u8* gfxTopLeftFramebuffers[2]; -extern u8* gfxSubFramebuffers[2]; +extern u8* gfxTopRightFramebuffers[2]; extern u8* gfxBottomFramebuffers[2]; extern u32* gxCmdBuf;