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/app_launch/source/main.c b/examples/app_launch/source/main.c index 807cb39..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 - gfxInit(); // Init graphic stuff - hidInit(NULL); // For input (buttons, touchscreen...) + gfxInitDefault(); // Init graphic stuff // 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/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 95% rename from examples/mic/source/main.c rename to examples/audio/mic/source/main.c index 89ece51..2726a75 100644 --- a/examples/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(); - gfxInit(); - hidInit(NULL); - + gfxInitDefault(); + 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/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..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(); - gfxInit(); - hidInit(NULL); + + gfxInitDefault(); //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/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/graphics/printing/hello-world/source/main.c b/examples/graphics/printing/hello-world/source/main.c index a954290..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(); - gfxInit(); - hidInit(NULL); + gfxInitDefault(); //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 bb93652..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(); @@ -87,19 +65,26 @@ int main() Result ret=0; httpcContext context; - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); - gfxInit(); - //gfxSet3D(true); // uncomment if using stereoscopic 3D + gfxInitDefault(); 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); } @@ -123,9 +108,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 d4244a3..0e03373 100644 --- a/examples/libapplet_launch/source/main.c +++ b/examples/libapplet_launch/source/main.c @@ -4,11 +4,7 @@ int main() { u32 val, i; - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); - gfxInit(); + gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D val = 0x22447899; @@ -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 3908a18..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); - gfxInit(); - fsInit(); - sdmcInit(); + gfxInitDefault(); //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 5464a42..252e352 100644 --- a/examples/qtm/source/main.c +++ b/examples/qtm/source/main.c @@ -11,11 +11,7 @@ int main() qtmHeadtrackingInfo qtminfo; u32 colors[4] = {0x0000FF, 0x00FF00, 0xFF0000, 0xFFFFFF}; - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); - gfxInit(); + gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D qtmInit(); @@ -84,9 +80,6 @@ int main() // Exit services qtmExit(); gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } 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/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; diff --git a/examples/templates/application/source/main.c b/examples/templates/application/source/main.c index df717a6..633c7ff 100644 --- a/examples/templates/application/source/main.c +++ b/examples/templates/application/source/main.c @@ -4,11 +4,7 @@ int main() { - // Initialize services - srvInit(); - aptInit(); - hidInit(NULL); - gfxInit(); + gfxInitDefault(); //gfxSet3D(true); // uncomment if using stereoscopic 3D // Main loop @@ -36,10 +32,6 @@ int main() gfxSwapBuffers(); } - // Exit services gfxExit(); - hidExit(); - aptExit(); - srvExit(); return 0; } 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 diff --git a/libctru/data/default_font.bin b/libctru/data/default_font.bin index 73436fc..e3ae20b 100644 Binary files a/libctru/data/default_font.bin and b/libctru/data/default_font.bin differ 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/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/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/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)) 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; 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; diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c index 9c9aded..0688804 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,23 @@ void gfxWriteFramebufferInfo(gfxScreen_t screen) framebufferInfoHeader[0x1]=1; } -void gfxInit() +void (*screenFree)(void *) = NULL; + +void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomFormat, bool vrambuffers) { + void *(*screenAlloc)(size_t); + + if (vrambuffers) + { + screenAlloc=vramAlloc; + screenFree=vramFree; + + } else { + + screenAlloc=linearAlloc; + screenFree=linearFree; + } + gspInit(); gfxSharedMemory=(u8*)0x10002000; @@ -117,15 +133,22 @@ 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; + //set requested modes + gfxSetScreenFormat(GFX_TOP,topFormat); + gfxSetScreenFormat(GFX_BOTTOM,bottomFormat); + //initialize framebuffer info structures gfxSetFramebufferInfo(GFX_TOP, 0); gfxSetFramebufferInfo(GFX_BOTTOM, 0); @@ -143,18 +166,24 @@ void gfxInit() GSPGPU_SetLcdForceBlack(NULL, 0x0); } +void gfxInitDefault() { + gfxInit(GSP_BGR8_OES,GSP_BGR8_OES,false); +} + 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); @@ -167,6 +196,8 @@ void gfxExit() GSPGPU_ReleaseRight(NULL); gspExit(); + + screenFree = NULL; } u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* height) @@ -185,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() 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; } 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