devkitpro / libctru Goto Github PK
View Code? Open in Web Editor NEWHomebrew development library for Nintendo 3DS/Horizon OS user mode (Arm11)
Home Page: https://libctru.devkitpro.org/
Homebrew development library for Nintendo 3DS/Horizon OS user mode (Arm11)
Home Page: https://libctru.devkitpro.org/
This line:
cmdbuf[6]=(l1<<4)|0xA;
Should be:
cmdbuf[6]=(l2<<4)|0xA;
Cf. https://github.com/citra-emu/citra/issues/91.
Being able to print some debug string wouldn't just be useful for us to debug homebrew by citra, but it would also be useful for homebrew developers to debug homebrew applications as a simple mean to do "printf"-style debugging.
I don't think implementing this function has any drawbacks, so it would be greatly appreciated if this worked out of the box :)
I have a tentative patch (no idea if it's to any extent sensible or correct, but it worked well enough for the citra implementation - but no idea if citra emulates calls to this service in existing applications properly), but it's written against the master branch. I'll just throw my bits here anyway, maybe they spare some time for someone who is willing to finish it.
First off, the function signature to include in a header is Result svc_outputDebugString(const char* str, int foo)
(I have no idea what "foo" is used for, but the parameter is said to exist on 3dbrew)
My implementation in libctru/source/svc.s
looks like this:
.global svc_outputDebugString
.type svc_outputDebugString, %function
svc_outputDebugString:
str r0, [sp,#-0x4]!
svc 0x3D
ldr r2, [sp], #4
str r1, [r2]
bx lr
ctrulib is missing some contributing guide for coding style and rules.
A draft is available at https://gist.github.com/Lectem/8a418268912521c35a3e
This would be part of the great-refactor, but we need people to reach some kind of consensus.
Please comment/vote here but keep in mind that we need to roughly keep a style close to the current code base.
Please also include the gist revision when commenting so that it is easier to track comments and changes.
clang-format is not mandatory but would help to refactor and act as a reference for pull requests.
For archiving reasons, I'm adding the original draft in this post.
if else
blocks#pragma once
for headersdefine
and enum
members are in SNAKE_UPPER_CASEEverything not mentioned here falls into the provided .clang-format
style. See Clang Format Style Options.
/**
* @file file.h
* @brief the @file is needed to expose the documentation in doxygen. Please document the headers
* and not the source code
*/
// Use #pragma once instead of guards for headers
#pragma once
#define BIT(n) (1U << (n))
#define RGB8_to_565(r, g, b) \
(((b) >> 3) & 0x1F) | ((((g) >> 2) & 0x3F) << 5) | ((((r) >> 3) & 0x1F) << 11)
typedef enum
{
FIRST_VALUE = 1, ///< This describes FIRST_VALUE
SECOND_VALUE = 2,
VALUE_IS_FIVE = 5, // Note the trailing comma
} SomeEnum;
/// brief description uses c++ style comments if fits in one line
int foo(void);
/**
* @brief Short description
* @param param1 information about the 1st param
* @param bool A pointer
*
* More information about this beautiful function.
*/
int tryit(int param1, bool *done);
static void bar(int hello, int folks)
{
int var = 0;
if(folks >= 1)
foo();
else if(somecond && (mustBeOne == 1))
{
sit();
wait();
}
switch(var)
{
case 0: break;
case 1:
doSomething();
doSomeMore();
break;
case 2: foo(); break;
default: break;
}
u32 address = (u32)ptr;
ptr[offset] = 0;
ptr[offset + 1] = 0;
}
---
IndentWidth: 4
TabWidth: 4
UseTab: ForIndentation
IndentCaseLabels: true
AlignConsecutiveAssignments: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
BinPackArguments: true
BinPackParameters: true
BreakBeforeBraces: Allman
ColumnLimit: 100
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 3
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Never
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Tested with yeti3DS (newest version from master branch).
When installed as app on the home menu launching works fine, but once it runs, it doesn't recive any signal anymore (pressing the Home or power button does nothing. It just runs as if nothing happened).
โฌ:
Launched with Home menu sleep mode works fine and repairs the broken signal stuff somehow (Home button and power off button are working again). Nevermind. Was luck. Return to home did work 2 times.
mkdir("/somepath//smth/", 0755)
This fails, inconsistent with POSIX mkdir.
The mic example's README says it can record roughly 32 seconds of audio. But when I try it, it only plays back a couple seconds of audio, nothing at all, or some duration between the two.
This may not be a proper solution (I wouldn't know), but it turns out if you take line 58 of main.c:
audiobuf_pos+= MIC_ReadAudioData(&audiobuf[audiobuf_pos], audiobuf_size-audiobuf_pos, 1);
and change that final argument waitforevent
from 1 to 0, it'll record and play back the full 32 seconds pretty much fine.
Example was compiled with devkitARM r44 with latest ctrulib and launched via TubeHax on a 3DS XL with firmware 10.0.0-27. (Same thing happened on 9.9.0-26 too.)
Calling this on an O3DS returns me 1 as return value ( http://3dbrew.org/wiki/Cfg:GetSystemModel )
It seems socketing is corrupted if used with some other services on with NH 2.X and relative haxs.
The same code working fine on 1.1b report errors when sending for server-type sockets and connecting for client-type sockets for my LUA interpreter (for example FTP give ECONNREFUSED on NH 2.x and Socket.connect() gives "Failed connecting server" error when executing this piece of code:
int err = connect(my_socket->sock, (struct sockaddr*)&my_socket->addrTo, sizeof(my_socket->addrTo));
if (err < 0 ) return luaL_error(L, "Failed connecting server.");
As the title says. On 3DSX executables, it works correctly but on CIA/3DS seems not. Any suggestion?
Seems first mute second is still here with microphone. This is the code i'm using that gives that problem: http://pastebin.com/58biXMur
While reworking my gpsp port's file code I found that chdir has a borked behavior in that it cannot chdir to relative file locations. As an example, doing a chdir(".");
will actually cause ctrulib to crash to home. Same with chdir("..");
. Even if you try to chdir to an exiting directory within the current working directory, it will crash. A simple test to check against this bug is just a chdir(".")
after initializing sdmc.
Also, getcwd seems to return "/" initially rather than "sdmc:/", up until you explicitly chdir("sdmc:/")
. Doesn't seem to affect anything, but it's there. I believe @mtheall is the one I should be talking with on this issue.
in the gpu example some files are missing. Just to read the sources
Can u add them, please?
Im trying to use SOC_Initialize but it fails always, is there a bug? I cant find memalign, it is used in all socket's examples, and Im using instead linearMemAlign. Can you help me, please?
When opening http contexts to perform file downloads, every attempt after the 8th fails consistently, with the same error code, somewhere during the call to httpcOpenContext.
To reproduce this, I modified the http download example, and got it to repeatedly download files in a loop. It's hosted here: http://darknovagames.com:1337/3ds/http_context_test.zip. This is fairly straightforward; run the code, press A repeatedly, and after the 8th call to httpcOpenContext(), it fails consistently.
I'm testing on a 3DS XL, using firmware version 9.2.0-20U. This is through Ninjhax; I lack the ability to test on anything else. This is pretty weird; it feels like a resource is not being released somewhere, but httpcCloseContext() is definitely being called.
https://github.com/smealum/ctrulib/blob/master/libctru/source/gpu/gpu.c#L218
void GPUCMD_Run(u32* gxbuf)
wants gxbuf, i.e. the GSP command buffer, as argument but is given the GPU command buffer gpuBuf
instead.
I have tracked down the use of this gxbuf
argument until GX_SetCommandList_First
and GSPGPU_SubmitGxCommand
and it does not seem it is a misnamed variable.
#143 with 73e0267 tried a simple fix but it broke the gpu, see image (it was merged a bit too fast)
GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h);
should be
GPU_SetScissorTest(GPU_SCISSORMODE mode, u32 x, u32 y, u32 x1, u32 y1);
The "w" and "h" are misleading as they imply width and height, but the format accepted by GPU_SetScissorTest are screen coordinates, thus
GPU_SetScissorTest(GPU_SCISSOR_NORMAL, x, y, x + width, y + height);
produces the desired result, otherwise if x == width or y == height, nothing is drawn.
Last working version is smealum/aemstro@55bf505 . After that, trying to build yields these error messages:
~/devkitPro/ctrulib_refactor/examples/gpu> make
test.vsh
inconsisten uniform register assignment !
inconsisten uniform register assignment !
Traceback (most recent call last):
File "aemstro/aemstro_as.py", line 503, in <module>
parseLine(dvlb.getDVLP(), dvle, line, False)
File "aemstro/aemstro_as.py", line 481, in parseLine
dirList[name](dvlp, dvle, r.group(2))
File "aemstro/aemstro_as.py", line 432, in parseUniform
dvle.addInput((int(s[0][1:],0)+offset,int(s[1][1:],0)+offset,s[2]))
ValueError: invalid literal for int() with base 0: ''
examples/gpu/Makefile:158: recipe for target 'test.vsh.o' failed
make[1]: *** [test.vsh.o] Error 1
Makefile:122: recipe for target 'build' failed
make: *** [build] Error 2
Ok, it is switching to the SSL connection but httpcGetResponseStatusCode returns 0xd8a0a03c with statuscode c3460000, The request is on port 443 but I think the certificate is invalid, can you help me?
see https://github.com/Steveice10/GameYob/issues/17 and 76e47c0
I have a new 3DS XL with hax 2.5 and firmware 10.2.0-28E
Building FTP-3DS with recent ctrulib versions yields a application which lacks input support. In particular, FTP-3DS doesn't detect any button presses, but still works fine other than that. From quick testing it seems this also affects (all?) other applications.
It was suggested on IRC that this is a regression from 9fe9493 . I did not specifically confirm this, but I can tell that c765e3b does not have the issue.
I'm assuming this isn't a "private" function, as it's the only way (AFAIK) to display the characters that are given special handling (tab, newline, etc.)
Another problem came with ndsp. After finishing adapting all my codes from csnd to dsp and checking all the functions work fine on a simple test script, i tried to use the new 3dsx file with Sunshell and this is the result: https://www.youtube.com/watch?v=MYZD5By1RUE
The issues came also on NH 1.1B:
I tried GPU sample with different configurations and i still get black screen, i tried to boot it on:
Are there some limitations on compatible firmwares?
Actually calling this function while the channel is playing some audio doesn't seem to stop playback.
specifically, calling DSP_UnloadComponent
when the status is still APP_NOTINITIALIZED
seems to be the problem.
this doesn't affect 3dsx builds started from the HBL currently since they start with the APP_RUNNING
status.
adding
if(!aptGetStatus())
aptWaitStatusEvent();
before this line https://github.com/smealum/ctrulib/blob/great-refactor/libctru/source/services/dsp.c#L17 prevents the deadlock.
After updating to last commits which included the FS service refactor, something like 70% of the executive code of my lua interpreter got completely broken.
Examples: Pause & Closing a sound cause a system crash. (This never happened before and there weren't syntax changes in the code).
I wonder if it could be caused by the FS_ATTRIBUTE_NONE that now is not usable anymore cause deprecated (?).
Please
For example, lets say I have a file called "audio.bin", that has already been tested and does indeed play correctly. If I were to load "audio.bin" from the root directory (/audio.bin), CSND would execute correctly. However, if I were to move it to a directory lower than 1 level (/folder1/folder2/audio.bin), it won't load at all, even if it is the same file. I've already checked the directory names against my code, and they do match up, so it has to be CSND.
looking at https://github.com/smealum/ctrulib/blob/master/libctru/include/3ds/services/am.h currently and i don't like the name of the structure. two things :
if noone objects I'll be making these changes pretty soon. mostly posting this issue in case someone has a preference regarding the name and so that there's a record of the change for people who already use that code.
On 3DBrew.org there are infos about the SSL sevice, can you add these features?
Why not adding different charsets support (like UTF-8 and Latin1(ISO-8859-1)) to libctru functions? (Maybe using LC_COLLATE category returned by standard C setlocale function to interchange charset to use)
totally unimportant but i was going through some examples and noticed this : https://github.com/smealum/ctrulib/blob/master/examples/graphics/printing/hello-world/source/main.c#L5-L12
basically i don't think that has anything to do in a source file and should be removed; imo that header should at most contain a description of the example, the author's name and last time modified. if someone wants to see a "big thanks to..." they should look in the readme file imo.
on a equally unimportant note, maybe switch that thing to use // comments rather than /* ?
-wrong tab sorry
I'm trying to port luaSound module of my interpreter to dsp service (cause csnd:SND seems broken for most things). I can successfully init ndsp ( https://github.com/Rinnegatamante/lpp-3ds/blob/master/source/luaSound.cpp#L974-L992 ) but when i try to play a mono WAV file (PCM-16 encoded) i get no sound ( https://github.com/Rinnegatamante/lpp-3ds/blob/master/source/luaSound.cpp#L1027-L1043 ).
Hi, i'm getting black screen freeze for thread sample on both real hardware and Citra.
So yeah, you'll probably hate me for spamming this issue tracker, as this is not really a bug in ctrulib, but I have no idea how to contact fincs so I'm just posting this here in hopes that somebody with the right contacts will notice.
The issue is this:
ld
has this really nice flag, --gc-sections
which, when used with the right compiler flags, does wonders to eliminate unreferenced functions and data. However, when used with the 3ds script linked in this repo's readme, the application crashes on exit.
This is because a section needed by the CRT is accidentally dropped and bad things happen.
The fix is so simple that even I was able to figure it out. In 3dsx.ld
, the following 3 lines need to be added just before /* =========== RODATA section =========== */
:
.fini ALIGN(4) :
{
KEEP( *(.fini) )
}
This preserves the required section and makes everybody happy.
Once again, sorry for opening this issue here, but I couldn't think of any better place.
Launching a homebrew app build with ctrulib results sometimes in a blackscreen. The app itself works/responds to button presses in this state. The 3DS just displays nothing. Return to home menu and continuing the app fixes it and everything get's displayed properly.
This only happens with standalone titles directly installed to the 3DS system.
It seems that my 3DS (9.2.0-20, Ninjhax) freezes whenever a httpc context is closed with httpcCloseContext
, even in the HTTP example in this repo. To make sure, I placed this code after the call and nothing came up:
printf("Closed context!");
gfxFlushBuffers();
On 3dmoo, it does not crash, however this is shown in the log:
>> svcSendSyncRequest (0x32)
http_c_SyncRequest (line 217): CloseContext 0dadbb17 --stub--
>> svcCloseHandle (0x23)
svcCloseHandle: svcCloseHandle undefined for handle-type "service".
Would be great if this could be solved.
Will patches implementing standard C libraries (stdlib, stdio, math etc) be accepted?
Is there already another project for that?
Thanks.
I saw a few places where values are not masked while nintendo uses STRB or STRH. We should also make sure that all bool types are masked using 0xFF.
Enum values should be masked depending on the smallest value (usually 0xFF or 0xFFFF). While gcc already stores most of those in bytes or halfwords, it is not guaranteed by the standard.
For example I spotted https://github.com/Steveice10/ctrulib/blob/service-cleanup/libctru/source/services/cam.c#L355 but there are probably many other services suffering from this issue.
The URL in the readme for the devkitARM patch necessary to get a build system for ctrulib up and running is broken (http://mtheall.com/%7Efincs/3dsdkA/ resolves to 404). It's not really within your control, but it's important to making setup as easy as possible for new developers.
Running the mic example on my N3DS causes "Init success" to be printed to the console, then crashes.
We need to support O_TRUNC in sdmc_open().
Returns: 0xC92044FA
This is consistent for more than just the romfs example code.
On the current version of ctrulib with the current version of picasso, none of the GPU examples can build because the output file needs to be specified with the current version of picasso.
But if you downgrade to a version of picasso that doesn't need that, you get an error along the lines of
gpu.c
arm-none-eabi-gcc -MMD -MP -MF /home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/build/gpu.d -g -Wall -O2 -mword-relocations -fomit-frame-pointer -ffast-math -march=armv6k -mtune=mpcore -mfloat-abi=hard -I/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/include -I/home/witheld/devkitPro/libctru/include -I/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/build -DARM11 -D_3DS -c /home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c -o gpu.o
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c: In function 'gpuClearBuffers':
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:31:45: error: 'GX_FILL_TRIGGER' undeclared (first use in this function)
colorBuf, clearColor, &colorBuf[240*400], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH,
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:31:45: note: each undeclared identifier is reported only once for each function it appears in
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:31:63: error: 'GX_FILL_32BIT_DEPTH' undeclared (first use in this function)
colorBuf, clearColor, &colorBuf[240*400], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH,
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c: In function 'gpuFrameEnd':
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: warning: implicit declaration of function 'GX_TRANSFER_FLIP_VERT' [-Wimplicit-function-declaration]
DISPLAY_TRANSFER_FLAGS);
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: warning: implicit declaration of function 'GX_TRANSFER_OUT_TILED' [-Wimplicit-function-declaration]
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: warning: implicit declaration of function 'GX_TRANSFER_RAW_COPY' [-Wimplicit-function-declaration]
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: warning: implicit declaration of function 'GX_TRANSFER_IN_FORMAT' [-Wimplicit-function-declaration]
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:5:24: error: 'GX_TRANSFER_FMT_RGBA8' undeclared (first use in this function)
GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: note: in expansion of macro 'DISPLAY_TRANSFER_FLAGS'
DISPLAY_TRANSFER_FLAGS);
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: warning: implicit declaration of function 'GX_TRANSFER_OUT_FORMAT' [-Wimplicit-function-declaration]
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:5:72: error: 'GX_TRANSFER_FMT_RGB8' undeclared (first use in this function)
GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: note: in expansion of macro 'DISPLAY_TRANSFER_FLAGS'
DISPLAY_TRANSFER_FLAGS);
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: warning: implicit declaration of function 'GX_TRANSFER_SCALING' [-Wimplicit-function-declaration]
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:6:22: error: 'GX_TRANSFER_SCALE_NO' undeclared (first use in this function)
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))
^
/home/witheld/Downloads/ctrulib/examples/graphics/gpu/geoshader/source/gpu.c:76:3: note: in expansion of macro 'DISPLAY_TRANSFER_FLAGS'
DISPLAY_TRANSFER_FLAGS);
^
/home/witheld/devkitPro/devkitARM/base_rules:84: recipe for target 'gpu.o' failed
make[1]: *** [gpu.o] Error 1
Makefile:127: recipe for target 'build' failed
make: *** [build] Error 2
The first call to memalign returns a valid-looking value, but attempting to use the memory causes a crash. Subsequent calls to memalign return valid values, but using them succeeds as one might expect.
Here's an example function I am testing to initialize sockets on the system:
void initialize_sockets() {
u32* first_bank = (u32*)memalign(0x1000, 0x100000);
if (first_bank == nullptr) {
debug_message("first memalign failed");
return;
}
debug_message("first bank: " + string_from<unsigned int>((unsigned int)first_bank, true));
u32* second_bank = (u32*)memalign(0x1000, 0x100000);
if (second_bank == nullptr) {
debug_message("second memalign failed");
return;
}
debug_message("second bank: " + string_from<unsigned int>((unsigned int)second_bank, true));
u32 ret = SOC_Initialize(second_bank, 0x100000);
debug_message(string_from<unsigned int>(ret));
}
Sample output on my system:
first bank: 0x8001000
second bank: 0x8102000
Modifying the code to pass first_bank in to SOC_Initialize causes it to crash. This is built against ctrulib version 74c37b4
Not sure what's going on; I suspect this has something to do with the recent changes to handle executable data regions perhaps?
Having a looped sound playing with csnd when a homebrew application is quitting causes some funky behaviour.
When loading other homebrew, high pitched noises can be heard, and loading other homebrew that uses sound can cause distortion.
Loading the homebrew the looped sound originated from causes the sound to be played, even if it shouldn't be.
I don't have good footage, but @shutterbug2000 recorded a similar issue with BreadBox https://www.youtube.com/watch?v=BPf4AUWewqM
Even stopping all channels on exit doesn't fix it.
It seems to crash most of the time, but earlier I encountered a problem where it simply made the while *printf family not working with format specifiers.
I don't know if there is a quickfix for that but it'd be nice if using printf before redirecting stdout (with consoleInit or else) would do nothing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.