From 39605bc6e216e29fc68ad424d861a6fe5476714d Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Fri, 2 Jan 2015 22:40:47 +0000 Subject: [PATCH 01/16] add macros for packing and aligning --- libctru/include/3ds/types.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libctru/include/3ds/types.h b/libctru/include/3ds/types.h index 2f7d01a..550c0d2 100644 --- a/libctru/include/3ds/types.h +++ b/libctru/include/3ds/types.h @@ -42,3 +42,9 @@ typedef s32 Result; typedef void (*ThreadFunc)(u32); #define BIT(n) (1U<<(n)) + +//! aligns a struct (and other types?) to m, making sure that the size of the struct is a multiple of m. +#define ALIGN(m) __attribute__((aligned (m))) + +//! packs a struct (and other types?) so it won't include padding bytes. +#define PACKED __attribute__ ((packed)) From abfb15af1bbe4d3ea8a5798ea97c26a70bbb9d01 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Fri, 2 Jan 2015 22:41:48 +0000 Subject: [PATCH 02/16] use struct for channel status array --- libctru/include/3ds/services/csnd.h | 24 +++++++++++++++++------- libctru/source/services/csnd.c | 10 +++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/libctru/include/3ds/services/csnd.h b/libctru/include/3ds/services/csnd.h index f607955..84201c9 100644 --- a/libctru/include/3ds/services/csnd.h +++ b/libctru/include/3ds/services/csnd.h @@ -1,30 +1,40 @@ #pragma once +#include <3ds/types.h> + #define CSND_SHAREDMEM_DEFAULT 0x10004000 typedef enum{ - CSND_LOOP_DISABLE, - CSND_LOOP_ENABLE + CSND_LOOP_DISABLE, + CSND_LOOP_ENABLE } CSND_LOOPING; typedef enum{ - CSND_ENCODING_PCM8, - CSND_ENCODING_PCM16, - CSND_ENCODING_IMA_ADPCM, - CSND_ENCODING_PSG//"3 = PSG, similar to DS?" + CSND_ENCODING_PCM8, + CSND_ENCODING_PCM16, + CSND_ENCODING_IMA_ADPCM, + CSND_ENCODING_PSG//"3 = PSG, similar to DS?" } CSND_ENCODING; +struct CSND_CHANNEL_STATUS { + u8 state; + u8 pad[3]; + u32 unknown; + u32 position; +} ALIGN(4); + //See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory Result CSND_initialize(u32* sharedMem); Result CSND_shutdown(); +u32 CSND_convertsamplerate(u32 samplerate); Result CSND_playsound(u32 channel, u32 looping, u32 encoding, u32 samplerate, u32 *vaddr0, u32 *vaddr1, u32 totalbytesize, u32 unk0, u32 unk1); void CSND_setchannel_playbackstate(u32 channel, u32 value); void CSND_sharedmemtype0_cmd0(u32 channel, u32 value); void CSND_writesharedmem_cmdtype0(u16 cmdid, u8 *cmdparams); Result CSND_sharedmemtype0_cmdupdatestate(int waitdone); -Result CSND_getchannelstate(u32 entryindex, u32 *out); +Result CSND_getchannelstate(u32 entryindex, struct CSND_CHANNEL_STATUS *out); Result CSND_getchannelstate_isplaying(u32 entryindex, u8 *status); diff --git a/libctru/source/services/csnd.c b/libctru/source/services/csnd.c index 52f95ec..d118329 100644 --- a/libctru/source/services/csnd.c +++ b/libctru/source/services/csnd.c @@ -301,14 +301,14 @@ Result CSND_playsound(u32 channel, u32 looping, u32 encoding, u32 samplerate, u3 return CSND_sharedmemtype0_cmdupdatestate(0); } -Result CSND_getchannelstate(u32 entryindex, u32 *out) +Result CSND_getchannelstate(u32 entryindex, struct CSND_CHANNEL_STATUS *out) { Result ret=0; if((ret = CSND_sharedmemtype0_cmdupdatestate(1))!=0)return ret; memcpy(out, &CSND_sharedmem[(CSND_sharedmem_cmdblocksize+8 + entryindex*0xc) >> 2], 0xc); - out[2] -= 0x0c000000; + out->position -= 0x0c000000; return 0; } @@ -316,12 +316,12 @@ Result CSND_getchannelstate(u32 entryindex, u32 *out) Result CSND_getchannelstate_isplaying(u32 entryindex, u8 *status) { Result ret; - u32 entry[0xc>>2]; + struct CSND_CHANNEL_STATUS entry; - ret = CSND_getchannelstate(entryindex, entry); + ret = CSND_getchannelstate(entryindex, &entry); if(ret!=0)return ret; - *status = entry[0] & 0xff; + *status = entry.state; return 0; } From 897498f0c16f53a200df3b84d1594774b90ffc79 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sat, 3 Jan 2015 00:02:49 +0000 Subject: [PATCH 03/16] add parameters to gfxInit, add gfxInitDefault function --- libctru/include/3ds/gfx.h | 3 ++- libctru/source/gfx.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/libctru/include/3ds/gfx.h b/libctru/include/3ds/gfx.h index 9cfcae0..1d0e545 100644 --- a/libctru/include/3ds/gfx.h +++ b/libctru/include/3ds/gfx.h @@ -19,7 +19,8 @@ typedef enum }gfx3dSide_t; //system stuff -void gfxInit(); +void gfxInitDefault(); +void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomFormat, bool vrambuffers); void gfxExit(); //control stuff diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c index 9c9aded..9047594 100644 --- a/libctru/source/gfx.c +++ b/libctru/source/gfx.c @@ -5,6 +5,7 @@ #include <3ds/gfx.h> #include <3ds/svc.h> #include <3ds/linear.h> +#include <3ds/vram.h> GSP_FramebufferInfo topFramebufferInfo, bottomFramebufferInfo; @@ -96,8 +97,20 @@ void gfxWriteFramebufferInfo(gfxScreen_t screen) framebufferInfoHeader[0x1]=1; } -void gfxInit() +void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomFormat, bool vrambuffers) { + void *(*screenAlloc)(size_t); + + if (vrambuffers) + { + screenAlloc=vramAlloc; + + } else { + + screenAlloc=linearAlloc; + + } + gspInit(); gfxSharedMemory=(u8*)0x10002000; @@ -117,13 +130,16 @@ void gfxInit() // if 3d enabled : // topright1 0x000FD200-0x00143700 // topright2 0x00143700-0x00189C00 + u32 topSize = 400 * 240 * __get_bytes_per_pixel(topFormat); + u32 bottomSize = 320 * 240 * __get_bytes_per_pixel(bottomFormat); + + gfxTopLeftFramebuffers[0]=screenAlloc(topSize); + gfxTopLeftFramebuffers[1]=screenAlloc(topSize); + gfxBottomFramebuffers[0]=screenAlloc(bottomSize); + gfxBottomFramebuffers[1]=screenAlloc(bottomSize); + gfxTopRightFramebuffers[0]=screenAlloc(topSize); + gfxTopRightFramebuffers[1]=screenAlloc(topSize); - gfxTopLeftFramebuffers[0]=linearAlloc(0x46500); - gfxTopLeftFramebuffers[1]=linearAlloc(0x46500); - gfxBottomFramebuffers[0]=linearAlloc(0x38400); - gfxBottomFramebuffers[1]=linearAlloc(0x38400); - gfxTopRightFramebuffers[0]=linearAlloc(0x46500); - gfxTopRightFramebuffers[1]=linearAlloc(0x46500); enable3d=false; //initialize framebuffer info structures @@ -143,6 +159,10 @@ void gfxInit() GSPGPU_SetLcdForceBlack(NULL, 0x0); } +void gfxInitDefault() { + gfxInit(GSP_BGR8_OES,GSP_BGR8_OES,false); +} + void gfxExit() { // Exit event handler From 81e93f867b3bbe701c20fdf3737e7cc4d90f5f24 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sat, 3 Jan 2015 00:06:22 +0000 Subject: [PATCH 04/16] update examples to use gfxInitDefault --- examples/app_launch/source/main.c | 2 +- examples/get_system_language/source/main.c | 2 +- examples/gpu/source/main.c | 2 +- examples/graphics/printing/hello-world/source/main.c | 2 +- examples/http/source/main.c | 2 +- examples/libapplet_launch/source/main.c | 2 +- examples/mic/source/main.c | 2 +- examples/mvd/source/main.c | 2 +- examples/qtm/source/main.c | 2 +- examples/sdmc/source/main.c | 2 +- examples/templates/application/source/main.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/app_launch/source/main.c b/examples/app_launch/source/main.c index 807cb39..d45b4ac 100644 --- a/examples/app_launch/source/main.c +++ b/examples/app_launch/source/main.c @@ -8,7 +8,7 @@ int main() { srvInit(); // Needed aptInit(); // Needed - gfxInit(); // Init graphic stuff + gfxInitDefault(); // Init graphic stuff hidInit(NULL); // For input (buttons, touchscreen...) diff --git a/examples/get_system_language/source/main.c b/examples/get_system_language/source/main.c index d0fa815..4cbb874 100644 --- a/examples/get_system_language/source/main.c +++ b/examples/get_system_language/source/main.c @@ -6,7 +6,7 @@ int main(int argc, char** argv) { // Initialize services - gfxInit(); + gfxInitDefault(); initCfgu(); diff --git a/examples/gpu/source/main.c b/examples/gpu/source/main.c index 5747637..887e249 100644 --- a/examples/gpu/source/main.c +++ b/examples/gpu/source/main.c @@ -192,7 +192,7 @@ int main(int argc, char** argv) //setup services srvInit(); aptInit(); - gfxInit(); + gfxInitDefault(); hidInit(NULL); //initialize GPU diff --git a/examples/graphics/printing/hello-world/source/main.c b/examples/graphics/printing/hello-world/source/main.c index a954290..6dd0a43 100644 --- a/examples/graphics/printing/hello-world/source/main.c +++ b/examples/graphics/printing/hello-world/source/main.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) // Initialize services srvInit(); aptInit(); - gfxInit(); + gfxInitDefault(); hidInit(NULL); //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one diff --git a/examples/http/source/main.c b/examples/http/source/main.c index bb93652..c51c44b 100644 --- a/examples/http/source/main.c +++ b/examples/http/source/main.c @@ -91,7 +91,7 @@ int main() srvInit(); aptInit(); hidInit(NULL); - gfxInit(); + gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D httpcInit(); diff --git a/examples/libapplet_launch/source/main.c b/examples/libapplet_launch/source/main.c index d4244a3..f7bc215 100644 --- a/examples/libapplet_launch/source/main.c +++ b/examples/libapplet_launch/source/main.c @@ -8,7 +8,7 @@ int main() srvInit(); aptInit(); hidInit(NULL); - gfxInit(); + gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D val = 0x22447899; diff --git a/examples/mic/source/main.c b/examples/mic/source/main.c index 89ece51..f54823f 100644 --- a/examples/mic/source/main.c +++ b/examples/mic/source/main.c @@ -15,7 +15,7 @@ int main() srvInit(); aptInit(); - gfxInit(); + gfxInitDefault(); hidInit(NULL); if(CSND_initialize(NULL)==0)audio_initialized = 1; diff --git a/examples/mvd/source/main.c b/examples/mvd/source/main.c index 3908a18..af8be2d 100644 --- a/examples/mvd/source/main.c +++ b/examples/mvd/source/main.c @@ -110,7 +110,7 @@ int main() srvInit(); aptInit(); hidInit(NULL); - gfxInit(); + gfxInitDefault(); fsInit(); sdmcInit(); //gfxSet3D(true); // uncomment if using stereoscopic 3D diff --git a/examples/qtm/source/main.c b/examples/qtm/source/main.c index 5464a42..7a8bfd6 100644 --- a/examples/qtm/source/main.c +++ b/examples/qtm/source/main.c @@ -15,7 +15,7 @@ int main() srvInit(); aptInit(); hidInit(NULL); - gfxInit(); + gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D qtmInit(); diff --git a/examples/sdmc/source/main.c b/examples/sdmc/source/main.c index b946f0a..7c91ab4 100644 --- a/examples/sdmc/source/main.c +++ b/examples/sdmc/source/main.c @@ -45,7 +45,7 @@ void renderEffect() int main(int argc, char** argv) { - gfxInit(); //makes displaying to screen easier + gfxInitDefault(); //makes displaying to screen easier FILE *file = fopen("test.bin","rb"); if (file == NULL) goto exit; diff --git a/examples/templates/application/source/main.c b/examples/templates/application/source/main.c index df717a6..d55fbe9 100644 --- a/examples/templates/application/source/main.c +++ b/examples/templates/application/source/main.c @@ -8,7 +8,7 @@ int main() srvInit(); aptInit(); hidInit(NULL); - gfxInit(); + gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D // Main loop From 2cc62ba17f1d617099c16b670a98b552c860c789 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sat, 3 Jan 2015 00:10:32 +0000 Subject: [PATCH 05/16] move mic example to audio subfolder --- examples/{ => audio}/mic/Makefile | 0 examples/{ => audio}/mic/README.md | 0 examples/{ => audio}/mic/source/main.c | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename examples/{ => audio}/mic/Makefile (100%) rename examples/{ => audio}/mic/README.md (100%) rename examples/{ => audio}/mic/source/main.c (100%) diff --git a/examples/mic/Makefile b/examples/audio/mic/Makefile similarity index 100% rename from examples/mic/Makefile rename to examples/audio/mic/Makefile diff --git a/examples/mic/README.md b/examples/audio/mic/README.md similarity index 100% rename from examples/mic/README.md rename to examples/audio/mic/README.md diff --git a/examples/mic/source/main.c b/examples/audio/mic/source/main.c similarity index 100% rename from examples/mic/source/main.c rename to examples/audio/mic/source/main.c From 6728df3556e2d5d4ce62a28b427e0a853446a072 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sat, 3 Jan 2015 00:25:00 +0000 Subject: [PATCH 06/16] one Makefile to rule them all --- examples/Makefile | 26 ++++++++++++++++++++++++++ examples/graphics/Makefile | 7 +++++++ examples/graphics/printing/Makefile | 7 +++++++ examples/templates/Makefile | 7 +++++++ 4 files changed, 47 insertions(+) create mode 100644 examples/Makefile create mode 100644 examples/graphics/Makefile create mode 100644 examples/graphics/printing/Makefile create mode 100644 examples/templates/Makefile diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..756d82d --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,26 @@ +SUBDIRS:= $(shell ls | egrep -v '^(CVS)$$') + +DATESTRING := $(shell date +%Y)$(shell date +%m)$(shell date +%d) + +#--------------------------------------------------------------------------------- +all: examples +#--------------------------------------------------------------------------------- + @rm -fr bin + @mkdir -p bin + @find . -name "*.3dsx" -exec cp -fv {} bin \; + +examples: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; + +#--------------------------------------------------------------------------------- +clean: +#--------------------------------------------------------------------------------- + @rm -fr bin + @rm -f *.bz2 + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; + +#--------------------------------------------------------------------------------- +dist: clean +#--------------------------------------------------------------------------------- + @rm -fr bin + @tar --exclude=.svn --exclude=*CVS* -cvjf 3ds-examples-$(DATESTRING).tar.bz2 * diff --git a/examples/graphics/Makefile b/examples/graphics/Makefile new file mode 100644 index 0000000..bce05ec --- /dev/null +++ b/examples/graphics/Makefile @@ -0,0 +1,7 @@ +SUBDIRS:= `ls | egrep -v '^(CVS)$$'` +all: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; +clean: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; +install: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i install || { exit 1;} fi; done; diff --git a/examples/graphics/printing/Makefile b/examples/graphics/printing/Makefile new file mode 100644 index 0000000..bce05ec --- /dev/null +++ b/examples/graphics/printing/Makefile @@ -0,0 +1,7 @@ +SUBDIRS:= `ls | egrep -v '^(CVS)$$'` +all: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; +clean: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; +install: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i install || { exit 1;} fi; done; diff --git a/examples/templates/Makefile b/examples/templates/Makefile new file mode 100644 index 0000000..bce05ec --- /dev/null +++ b/examples/templates/Makefile @@ -0,0 +1,7 @@ +SUBDIRS:= `ls | egrep -v '^(CVS)$$'` +all: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i || { exit 1;} fi; done; +clean: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i clean || { exit 1;} fi; done; +install: + @for i in $(SUBDIRS); do if test -e $$i/Makefile ; then $(MAKE) -C $$i install || { exit 1;} fi; done; From d6e0e5b198e8ebb472cf4eeb618f590817868ade Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sat, 3 Jan 2015 00:43:21 +0000 Subject: [PATCH 07/16] free screens from where they were allocated --- libctru/source/gfx.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c index 9047594..e7b6672 100644 --- a/libctru/source/gfx.c +++ b/libctru/source/gfx.c @@ -97,6 +97,8 @@ void gfxWriteFramebufferInfo(gfxScreen_t screen) framebufferInfoHeader[0x1]=1; } +void (*screenFree)(void *) = NULL; + void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomFormat, bool vrambuffers) { void *(*screenAlloc)(size_t); @@ -104,11 +106,12 @@ void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomForm if (vrambuffers) { screenAlloc=vramAlloc; + screenFree=vramFree; } else { screenAlloc=linearAlloc; - + screenFree=linearFree; } gspInit(); @@ -165,16 +168,18 @@ void gfxInitDefault() { void gfxExit() { + if (screenFree == NULL ) return; + // Exit event handler gspExitEventHandler(); // Free framebuffers - linearFree(gfxTopRightFramebuffers[1]); - linearFree(gfxTopRightFramebuffers[0]); - linearFree(gfxBottomFramebuffers[1]); - linearFree(gfxBottomFramebuffers[0]); - linearFree(gfxTopLeftFramebuffers[1]); - linearFree(gfxTopLeftFramebuffers[0]); + screenFree(gfxTopRightFramebuffers[1]); + screenFree(gfxTopRightFramebuffers[0]); + screenFree(gfxBottomFramebuffers[1]); + screenFree(gfxBottomFramebuffers[0]); + screenFree(gfxTopLeftFramebuffers[1]); + screenFree(gfxTopLeftFramebuffers[0]); //unmap GSP shared mem svcUnmapMemoryBlock(gspSharedMemHandle, 0x10002000); From 74c37b4e87286f40000dea00b529126af5a7d4b8 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sat, 3 Jan 2015 00:45:31 +0000 Subject: [PATCH 08/16] and protect from double exit --- libctru/source/gfx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c index e7b6672..a2e9583 100644 --- a/libctru/source/gfx.c +++ b/libctru/source/gfx.c @@ -192,6 +192,8 @@ void gfxExit() GSPGPU_ReleaseRight(NULL); gspExit(); + + screenFree = NULL; } u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* height) From ed72f9474b5fc6237a4b9b1eca558505d8bc5acf Mon Sep 17 00:00:00 2001 From: smea Date: Sat, 3 Jan 2015 18:00:55 -0800 Subject: [PATCH 09/16] fixed linear/vram mem align --- libctru/source/allocator/mem_pool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libctru/source/allocator/mem_pool.cpp b/libctru/source/allocator/mem_pool.cpp index 2c32638..a2c312d 100644 --- a/libctru/source/allocator/mem_pool.cpp +++ b/libctru/source/allocator/mem_pool.cpp @@ -39,6 +39,7 @@ bool MemPool::Allocate(MemChunk& chunk, u32 size, int align) { auto addr = b->base; u32 begWaste = (u32)addr & alignM; + if (begWaste > 0) begWaste = alignM + 1 - begWaste; addr += begWaste; u32 bSize = b->size - begWaste; if (bSize < size) continue; From 168d967743a2c039d6a49ba582ba286b2e14d977 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Sun, 4 Jan 2015 14:59:48 +0000 Subject: [PATCH 10/16] __libc_init_array needs run after stack adjustment, __libc_fini_array before original stack is restored --- libctru/source/system/ctru_exit.c | 3 --- libctru/source/system/initSystem.c | 5 ----- libctru/source/system/stack_adjust.s | 6 +++++- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/libctru/source/system/ctru_exit.c b/libctru/source/system/ctru_exit.c index f4c99f1..6cd4a38 100644 --- a/libctru/source/system/ctru_exit.c +++ b/libctru/source/system/ctru_exit.c @@ -15,9 +15,6 @@ void __attribute__((weak)) __attribute__((noreturn)) __libctru_exit(int rc) { u32 tmp=0; - // Run the global destructors - __libc_fini_array(); - __appExit(); // Unmap the linear heap diff --git a/libctru/source/system/initSystem.c b/libctru/source/system/initSystem.c index 501cfaa..c14c455 100644 --- a/libctru/source/system/initSystem.c +++ b/libctru/source/system/initSystem.c @@ -12,9 +12,6 @@ void __system_allocateHeaps(); void __system_initArgv(); void __appInit(); -// newlib definitions we need -void __libc_init_array(void); - void __ctru_exit(int rc); @@ -32,6 +29,4 @@ void __attribute__((weak)) __libctru_init(void (*retAddr)(void)) __appInit(); - // Run the global constructors - __libc_init_array(); } diff --git a/libctru/source/system/stack_adjust.s b/libctru/source/system/stack_adjust.s index 7c780fb..03513f0 100644 --- a/libctru/source/system/stack_adjust.s +++ b/libctru/source/system/stack_adjust.s @@ -16,12 +16,14 @@ initSystem: ldr sp, [r2] ldr r3, =__stacksize__ - ldr r3, [r3] + ldr r3, [r3] add sp, sp, r3 add sp, sp, #7 bics sp, sp, #7 str sp, [r2] + bl __libc_init_array + ldr r2, =saved_stack ldr lr, [r2,#4] bx lr @@ -31,6 +33,8 @@ initSystem: .type __ctru_exit, %function __ctru_exit: + bl __libc_fini_array + ldr r2, =saved_stack ldr sp, [r2] b __libctru_exit From 93de4971bdb7a4201149dd8efdf562042af3f222 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Tue, 6 Jan 2015 12:27:37 +0000 Subject: [PATCH 11/16] full 256 character font --- libctru/data/default_font.bin | Bin 2048 -> 2048 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/libctru/data/default_font.bin b/libctru/data/default_font.bin index 73436fc909db8bb3a7ca8af9133084e68c4f354e..e3ae20b324d5a53e08bdf62063e67cd2744475e1 100644 GIT binary patch literal 2048 zcmYjS&5GMr6h1_tY%caJFWAUX@&Fe^HG&EW@(%4HD}jPii0BLyW(4EPnO$FD9-y1P zLqK3~ySOCV0S{$XnN0{;&6r}We&4-v$&sa_bME=SpRPqbb=QAfzrVTex?wx4ABL_u z91hF$L{8GBe=_zEB?!}uZl&8xGwXJtnJB1ZFh9P=kr*Vk0C1llA+ev=u45RTK| zoFXOW<^3X7uObOZsHdu%wy7(@bU=kvm#eo`RY~>h)!7?x(&qKo^3xth?cVH-*;)JV=HuqC$xLTj-=3pi*Izo; z=LW#M^D+KT;9><4KJV|WWKEMxCpZV1RB#F!95k39hq~{3GTHMJTyN|@ac!sI+tag; z!FWVrn`&DVf_T-F6o?cJmI`xzp zCrO^1p4q&dBt9?XV?O7XB!$b1eBk&#{;#JP*9UM`b*%T;7waBIq9%p{=2UHBdVPQ2o{G9@^k2GM0Qn=y|k6yS__K3v@K h=W)n3xJ8}|`4s2Q=O&xCt_zWK1Z>@U1{w{){sXV$9)kb? literal 2048 zcmcIlO=}cE5G|ZxT$W}NmK++g^mrH)JV-<1xWr-FKn@;6@Sxx!5EvMPS>!f>obodI0d=RJk;2=#8c@tGfO03V_ zP4=mAIhW+GpUwzk9W38>a@IGt>CY6cwGx%rr8p?oIyv3LWQt5&L2=+_7;qZK(wHKB z6PK0f$CF<4FXB)Z`zfK9)I)?mu`L5bhrP_;ME?LLS!f~np@1u}R>Q8s9PdZ~F!?hc z`&YdM0Vy5^)dupx{5W`GHQxj})36S17=;m+rU{c*6+VWnYuj+Qix+&Mhwd;cmxrNl#fQy9sdCmUUPhQjI zSN^#v%p8_K=RcDlCymaLyAU@GP~?WreSNZNu?)82R4K!?)(eesa;BV4a2a?Tj#In6 z`)qd`^U7z{Od3|wpZB`h{&?sNEE%t2>~^co#jn~!jdiTY@WDl|w{RqZV) zx3V6vkBawpKFMjd|CKtrupZ}cl;d3E{N|&C zW}0xkk&ri$>nl6?Y^yt~_n{c&5f4Me{)A?lFyN)29q~bzV|+!#QAAut+>s-`FXIh; z81UX9+fWygbrG4Lc%}~p`W=q_>irz$SXTdpW|}bQy>asS+c0n5SKK#5!!uKR)Tj3z zc@&XH5&bKo&fn}Jo4KntLBF08qx|9iD1SiZiT4T5GT)0)jyCZwz1->ZFd9`s{eMNAO4oOR$I2=j1zi988Y|0Vn{*&UA5(0`)E*q<`c{pA1v From 0a3bb7bcadc0c63d5dfdf7ac22a4e650cdd9ad58 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Tue, 6 Jan 2015 12:28:16 +0000 Subject: [PATCH 12/16] allow for extenstion beyond 256 characters --- libctru/include/3ds/console.h | 2 +- libctru/source/console.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libctru/include/3ds/console.h b/libctru/include/3ds/console.h index 48c7224..816eb02 100644 --- a/libctru/include/3ds/console.h +++ b/libctru/include/3ds/console.h @@ -23,7 +23,7 @@ consoleInit() extern "C" { #endif -typedef bool(* ConsolePrint)(void* con, char c); +typedef bool(* ConsolePrint)(void* con, int c); //! a font struct for the console. typedef struct ConsoleFont diff --git a/libctru/source/console.c b/libctru/source/console.c index c6469f2..699f83a 100644 --- a/libctru/source/console.c +++ b/libctru/source/console.c @@ -43,7 +43,7 @@ PrintConsole defaultConsole = { (u8*)default_font_bin, //font gfx 0, //first ascii character in the set - 128 //number of characters in the font set + 256 //number of characters in the font set }, (u16*)NULL, 0,0, //cursorX cursorY @@ -68,7 +68,7 @@ PrintConsole* currentConsole = ¤tCopy; PrintConsole* consoleGetDefault(void){return &defaultConsole;} -void consolePrintChar(char c); +void consolePrintChar(int c); void consoleDrawChar(int c); //--------------------------------------------------------------------------------- @@ -672,7 +672,7 @@ void consoleDrawChar(int c) { } //--------------------------------------------------------------------------------- -void consolePrintChar(char c) { +void consolePrintChar(int c) { //--------------------------------------------------------------------------------- if (c==0) return; From 8087dc8aea1878a938d0e69631e66be350b53c24 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Tue, 6 Jan 2015 12:47:47 +0000 Subject: [PATCH 13/16] roll a new libctru release --- libctru/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libctru/Makefile b/libctru/Makefile index 5ee809b..279231c 100644 --- a/libctru/Makefile +++ b/libctru/Makefile @@ -9,7 +9,7 @@ endif include $(DEVKITARM)/base_rules export LIBCTRU_MAJOR := 0 -export LIBCTRU_MINOR := 2 +export LIBCTRU_MINOR := 3 export LIBCTRU_PATCH := 0 From a2ce1e13ca9c87c0b055abb1bd9dab5d63af7e25 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Wed, 7 Jan 2015 15:09:21 +0000 Subject: [PATCH 14/16] explicitly set screen modes, get flushbuffer size from mode --- libctru/source/gfx.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c index a2e9583..0688804 100644 --- a/libctru/source/gfx.c +++ b/libctru/source/gfx.c @@ -145,6 +145,10 @@ void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomForm enable3d=false; + //set requested modes + gfxSetScreenFormat(GFX_TOP,topFormat); + gfxSetScreenFormat(GFX_BOTTOM,bottomFormat); + //initialize framebuffer info structures gfxSetFramebufferInfo(GFX_TOP, 0); gfxSetFramebufferInfo(GFX_BOTTOM, 0); @@ -212,9 +216,12 @@ u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* hei void gfxFlushBuffers() { - GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x46500); - if(enable3d)GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), 0x46500); - GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), 0x38400); + u32 topSize = 400 * 240 * __get_bytes_per_pixel(gfxGetScreenFormat(GFX_TOP)); + u32 bottomSize = 320 * 240 * __get_bytes_per_pixel(gfxGetScreenFormat(GFX_BOTTOM)); + + GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), topSize); + if(enable3d)GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), topSize); + GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), bottomSize); } void gfxSwapBuffers() From 678b89e9b2e9c38fb5f66ce5b51476cf831f7a8b Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Fri, 9 Jan 2015 08:14:01 +0000 Subject: [PATCH 15/16] remove unneeded boilerplate from examples --- examples/app_launch/source/main.c | 7 --- examples/audio/mic/source/main.c | 8 +--- examples/gpu/source/main.c | 46 ++++++++----------- .../printing/hello-world/source/main.c | 10 +--- examples/http/source/main.c | 7 --- examples/libapplet_launch/source/main.c | 7 --- examples/mvd/source/main.c | 12 ----- examples/qtm/source/main.c | 7 --- examples/templates/application/source/main.c | 8 ---- 9 files changed, 22 insertions(+), 90 deletions(-) diff --git a/examples/app_launch/source/main.c b/examples/app_launch/source/main.c index d45b4ac..73cecb6 100644 --- a/examples/app_launch/source/main.c +++ b/examples/app_launch/source/main.c @@ -6,10 +6,7 @@ int main() { - srvInit(); // Needed - aptInit(); // Needed gfxInitDefault(); // Init graphic stuff - hidInit(NULL); // For input (buttons, touchscreen...) // We need these 2 buffers for APT_DoAppJump() later. They can be smaller too @@ -46,11 +43,7 @@ int main() } - // Deinit everything before the app process get's terminated - hidExit(); gfxExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/audio/mic/source/main.c b/examples/audio/mic/source/main.c index f54823f..2726a75 100644 --- a/examples/audio/mic/source/main.c +++ b/examples/audio/mic/source/main.c @@ -13,11 +13,8 @@ int main() u8 control=0x40; u32 audio_initialized = 0; - srvInit(); - aptInit(); gfxInitDefault(); - hidInit(NULL); - + if(CSND_initialize(NULL)==0)audio_initialized = 1; sharedmem = (u32*)memalign(0x1000, sharedmem_size); @@ -85,10 +82,7 @@ int main() free(sharedmem); linearFree(audiobuf); - hidExit(); gfxExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/gpu/source/main.c b/examples/gpu/source/main.c index 887e249..3662ccd 100644 --- a/examples/gpu/source/main.c +++ b/examples/gpu/source/main.c @@ -114,13 +114,13 @@ const vertex_s modelVboData[]= //stolen from staplebutt void GPU_SetDummyTexEnv(u8 num) { - GPU_SetTexEnv(num, - GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0), - GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0), - GPU_TEVOPERANDS(0,0,0), - GPU_TEVOPERANDS(0,0,0), - GPU_REPLACE, - GPU_REPLACE, + GPU_SetTexEnv(num, + GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0), + GPU_TEVSOURCES(GPU_PREVIOUS, 0, 0), + GPU_TEVOPERANDS(0,0,0), + GPU_TEVOPERANDS(0,0,0), + GPU_REPLACE, + GPU_REPLACE, 0xFFFFFFFF); } @@ -128,31 +128,31 @@ void GPU_SetDummyTexEnv(u8 num) void renderFrame() { GPU_SetViewport((u32*)osConvertVirtToPhys((u32)gpuDOut),(u32*)osConvertVirtToPhys((u32)gpuOut),0,0,240*2,400); - + GPU_DepthRange(-1.0f, 0.0f); GPU_SetFaceCulling(GPU_CULL_BACK_CCW); GPU_SetStencilTest(false, GPU_ALWAYS, 0x00, 0xFF, 0x00); GPU_SetStencilOp(GPU_KEEP, GPU_KEEP, GPU_KEEP); GPU_SetBlendingColor(0,0,0,0); GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL); - - GPUCMD_AddSingleParam(0x00010062, 0); + + GPUCMD_AddSingleParam(0x00010062, 0); GPUCMD_AddSingleParam(0x000F0118, 0); - + //setup shader SHDR_UseProgram(shader, 0); - + GPU_SetAlphaBlending(GPU_BLEND_ADD, GPU_BLEND_ADD, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA); GPU_SetAlphaTest(false, GPU_ALWAYS, 0x00); - + GPU_SetTextureEnable(GPU_TEXUNIT0); - - GPU_SetTexEnv(0, - GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), + + GPU_SetTexEnv(0, GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), - GPU_TEVOPERANDS(0,0,0), - GPU_TEVOPERANDS(0,0,0), - GPU_MODULATE, GPU_MODULATE, + GPU_TEVSOURCES(GPU_TEXTURE0, GPU_PRIMARY_COLOR, GPU_PRIMARY_COLOR), + GPU_TEVOPERANDS(0,0,0), + GPU_TEVOPERANDS(0,0,0), + GPU_MODULATE, GPU_MODULATE, 0xFFFFFFFF); GPU_SetDummyTexEnv(1); GPU_SetDummyTexEnv(2); @@ -189,11 +189,8 @@ void renderFrame() int main(int argc, char** argv) { - //setup services - srvInit(); - aptInit(); + gfxInitDefault(); - hidInit(NULL); //initialize GPU GPU_Init(NULL); @@ -321,9 +318,6 @@ int main(int argc, char** argv) } gsExit(); - hidExit(); gfxExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/graphics/printing/hello-world/source/main.c b/examples/graphics/printing/hello-world/source/main.c index 6dd0a43..c131d20 100644 --- a/examples/graphics/printing/hello-world/source/main.c +++ b/examples/graphics/printing/hello-world/source/main.c @@ -17,16 +17,12 @@ int main(int argc, char **argv) { - // Initialize services - srvInit(); - aptInit(); gfxInitDefault(); - hidInit(NULL); //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one consoleInit(GFX_TOP, NULL); - //Move the cursor to row 15 and column 19 and then prints "Hello World!" + //Move the cursor to row 15 and column 19 and then prints "Hello World!" //To move the cursor you have tu print "\x1b[r;cH", where r and c are respectively //the row and column where you want your cursor to move //The top screen has 30 rows and 50 columns @@ -54,10 +50,6 @@ int main(int argc, char **argv) gspWaitForVBlank(); } - // Exit services gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/http/source/main.c b/examples/http/source/main.c index c51c44b..ed7b867 100644 --- a/examples/http/source/main.c +++ b/examples/http/source/main.c @@ -87,10 +87,6 @@ int main() Result ret=0; httpcContext context; - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D httpcInit(); @@ -123,9 +119,6 @@ int main() // Exit services httpcExit(); gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/libapplet_launch/source/main.c b/examples/libapplet_launch/source/main.c index f7bc215..0e03373 100644 --- a/examples/libapplet_launch/source/main.c +++ b/examples/libapplet_launch/source/main.c @@ -4,10 +4,6 @@ int main() { u32 val, i; - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D @@ -42,9 +38,6 @@ int main() // Exit services gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/mvd/source/main.c b/examples/mvd/source/main.c index af8be2d..7e8aec4 100644 --- a/examples/mvd/source/main.c +++ b/examples/mvd/source/main.c @@ -106,13 +106,7 @@ void draw_startup() int main() { - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); gfxInitDefault(); - fsInit(); - sdmcInit(); //gfxSet3D(true); // uncomment if using stereoscopic 3D memset(logstring, 0, 256); @@ -143,13 +137,7 @@ int main() if(inaddr)linearFree(inaddr); if(outaddr)linearFree(outaddr); - // Exit services - sdmcExit(); - fsExit(); gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/qtm/source/main.c b/examples/qtm/source/main.c index 7a8bfd6..252e352 100644 --- a/examples/qtm/source/main.c +++ b/examples/qtm/source/main.c @@ -11,10 +11,6 @@ int main() qtmHeadtrackingInfo qtminfo; u32 colors[4] = {0x0000FF, 0x00FF00, 0xFF0000, 0xFFFFFF}; - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D @@ -84,9 +80,6 @@ int main() // Exit services qtmExit(); gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } diff --git a/examples/templates/application/source/main.c b/examples/templates/application/source/main.c index d55fbe9..633c7ff 100644 --- a/examples/templates/application/source/main.c +++ b/examples/templates/application/source/main.c @@ -4,10 +4,6 @@ int main() { - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D @@ -36,10 +32,6 @@ int main() gfxSwapBuffers(); } - // Exit services gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } From cecae02b1d5a500ab56c8bad2a2aee8776e30797 Mon Sep 17 00:00:00 2001 From: Dave Murphy Date: Fri, 9 Jan 2015 09:49:08 +0000 Subject: [PATCH 16/16] use console to display info, download from real url --- examples/http/source/main.c | 53 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/examples/http/source/main.c b/examples/http/source/main.c index ed7b867..2ef2bbe 100644 --- a/examples/http/source/main.c +++ b/examples/http/source/main.c @@ -1,27 +1,18 @@ #include #include +#include +#include #include <3ds.h> Result http_download(httpcContext *context)//This error handling needs updated with proper text printing once ctrulib itself supports that. { Result ret=0; - u8* framebuf_top, *framebuf_bottom; + u8* framebuf_top; u32 statuscode=0; u32 size=0, contentsize=0; u8 *buf; - framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); - memset(framebuf_bottom, 0x40, 240*320*3); - gfxFlushBuffers(); - gfxSwapBuffers(); - - framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); - memset(framebuf_bottom, 0x40, 240*320*3); - gfxFlushBuffers(); - gfxSwapBuffers(); - gspWaitForVBlank(); - ret = httpcBeginRequest(context); if(ret!=0)return ret; @@ -33,23 +24,13 @@ Result http_download(httpcContext *context)//This error handling needs updated w ret=httpcGetDownloadSizeState(context, NULL, &contentsize); if(ret!=0)return ret; + printf("size: %"PRId32"\n",contentsize); + gfxFlushBuffers(); + buf = (u8*)malloc(contentsize); if(buf==NULL)return -1; memset(buf, 0, contentsize); - framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); - memset(framebuf_bottom, 0xc0, 240*320*3); - gfxFlushBuffers(); - gfxSwapBuffers(); - - framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); - memset(framebuf_bottom, 0xc0, 240*320*3); - gfxFlushBuffers(); - gfxSwapBuffers(); - gspWaitForVBlank(); - - framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); - framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); ret = httpcDownloadData(context, buf, contentsize, NULL); if(ret!=0) @@ -59,18 +40,15 @@ Result http_download(httpcContext *context)//This error handling needs updated w } size = contentsize; - if(size>(240*400*3))size = 240*400*3; + if(size>(240*400*3*2))size = 240*400*3*2; - memset(framebuf_bottom, 0xff, 240*320*3); + framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); memcpy(framebuf_top, buf, size); gfxFlushBuffers(); gfxSwapBuffers(); framebuf_top = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); - framebuf_bottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL); - - memset(framebuf_bottom, 0xff, 240*320*3); memcpy(framebuf_top, buf, size); gfxFlushBuffers(); @@ -88,14 +66,25 @@ int main() httpcContext context; gfxInitDefault(); - //gfxSet3D(true); // uncomment if using stereoscopic 3D httpcInit(); - ret = httpcOpenContext(&context, "http://10.0.0.3/httpexample_rawimg.bin", 0);//Change this to your own URL. + consoleInit(GFX_BOTTOM,NULL); + + //Change this to your own URL. + char *url = "http://devkitpro.org/misc/httpexample_rawimg.rgb"; + + printf("Downloading %s\n",url); + gfxFlushBuffers(); + + ret = httpcOpenContext(&context, url , 0); + printf("return from httpcOpenContext: %"PRId32"\n",ret); + gfxFlushBuffers(); if(ret==0) { ret=http_download(&context); + printf("return from http_download: %"PRId32"\n",ret); + gfxFlushBuffers(); httpcCloseContext(&context); }