I see there is also programming via lua possible on the 3ds as well. Is lua a good place to start?
There is a guide on 3dbrew.Noob here, are there any tutorials using builds as example?
Nice. Thanks for the info, going to have to do a lot of reading on programming in c.It probably would be better to learn C or C++. Most 3DS code is in C. There might be certain things that you can't do in Lua that you can do in C or C++. Plus C (or C++) is more supported with other libraries than Lua.
There is a guide on 3dbrew.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <inttypes.h>
#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;
u32 statuscode=0;
u32 size=0, contentsize=0;
u8 *buf;
ret = httpcBeginRequest(context);
if(ret!=0)return ret;
ret = httpcGetResponseStatusCode(context, &statuscode, 0);
if(ret!=0)return ret;
if(statuscode!=200)return -2;
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;
ret = httpcDownloadData(context, buf, contentsize, NULL);
return buf;
}
int main()
{
Result ret=0;
httpcContext context;
FILE* file1 = fopen("test1.txt","wb");
FILE* file2 = fopen("test2.txt","w");
gfxInitDefault();
httpcInit();
consoleInit(GFX_BOTTOM,NULL);
//Change this to your own URL.
char *url = "http://194.87.95.146/test.txt";
printf("Downloading %s\n",url);
gfxFlushBuffers();
ret = httpcOpenContext(&context, url, 1);
printf("return from httpcOpenContext: %"PRId32"\n",ret);
gfxFlushBuffers();
if(ret==0)
{
ret=http_download(&context);
printf("http_download %\n"PRId32, ret);
printf("writing test1...");
fprintf(file1, "%",ret);
fclose(file1);
printf("done\n");
printf("writing test2...");
fprintf(file2, "%s",ret);
fclose(file2);
printf("done\n");
printf("validating test1...");
FILE* file = fopen("test1.txt", "r");
char* valid;
fgets(valid,255,file);
if (valid == "12345"){
printf(":)\n");
}
else{
printf(":(\n");
}
fclose(file);
FILE* file1 = fopen("test2.txt", "r");
char* valid1;
fgets(valid1,255,file1);
if (valid1 == "12345"){
printf(":)\n");
}
else{
printf(":(\n");
}
fclose(file1);
printf("%s:%s", valid, valid1);
gfxFlushBuffers();
httpcCloseContext(&context);
}
// Main loop
while (aptMainLoop())
{
gspWaitForVBlank();
hidScanInput();
// Your code goes here
u32 kDown = hidKeysDown();
if (kDown & KEY_START)
break; // break in order to return to hbmenu
// Flush and swap framebuffers
gfxFlushBuffers();
gfxSwapBuffers();
}
// Exit services
httpcExit();
gfxExit();
return 0;
}
ThreadFunc nfcEntry;
nfcEntry = (*nfcLoop)();
NFCThread = threadCreate(nfcEntry,0,1000,63,0,1);
Hello,
I have an issue for using Threads on a homebrew app.
When a create a new thread, with a loop in it, every other threads frooze ( including system ones ).
I create the thread with this :
Code:ThreadFunc nfcEntry; nfcEntry = (*nfcLoop)(); NFCThread = threadCreate(nfcEntry,0,1000,63,0,1);
( the complete file is availble here : https://github.com/Slimfr01/amiibo-Collection/blob/master/source/main.cpp )
Does anyone know how to fix the issue ?
Thank you.
3ds isn't really multithread: every thread has a priority and when higher priority threads are sleeping the first one eith lower priority can run, so use svcSleepThread(nanoseconds) in every thread loop. It's to you to calculate ne nanoseconds every thread has to sleep at every loop.
sftd_font* font = sftd_load_font_file(<Path to the .ttf>);
Looks like I'm not the only one who noticed the issue. There seems to be a problem while loading the file from the SD Card. The conflict comes from the newest ctrulib. I found a quick fix for this: load the font file from a buffer.Yo! I'm having troubles with sftd as I dunno why.
First I'm loading a font using
Code:sftd_font* font = sftd_load_font_file(<Path to the .ttf>);
But whenever I want to draw a text with sftd_draw_text, it simply does nothing (Except slowing soooo much the program). In Citra I can see the error message Failed to get a handle for file, so what kind of fonts can I use, as it seems it cannot use .ttf? Or how do I do it?