Homebrew Homebrew Development

  • Thread starter Thread starter aliak11
  • Start date Start date
  • Views Views 1,475,000
  • Replies Replies 6,048
  • Likes Likes 54
Take in mind that my Bitmap framebuffer is encoded like a Bitmap file so is flipped.

Code:
void PrintScreenBitmap(int xp,int yp, Bitmap* result,int screen,int side){
if(!result) return;
u8* buffer = 0;
if (screen == 0){
if (side == 0) buffer = TopLFB;
else buffer = TopRFB;
}else if (screen == 1) buffer = BottomFB;
int x, y;
if (result->bitperpixel == 24){
for (y = 0; y < result->height; y++){
for (x = 0; x < result->width; x++){
u8 B = result->pixels[(x + (result->height - y - 1) * result->width)*3];
u8 G = result->pixels[(x + (result->height - y - 1) * result->width)*3 + 1];
u8 R = result->pixels[(x + (result->height - y - 1) * result->width)*3 + 2];
u32 color = B + G*256 + R*256*256;
DrawPixel(buffer,xp+x,yp+y,color);
}
}
}else{
for (y = 0; y < result->height; y++){
for (x = 0; x < result->width; x++){
u8 B = result->pixels[(x + (result->height - y - 1) * result->width)*4];
u8 G = result->pixels[(x + (result->height - y - 1) * result->width)*4 + 1];
u8 R = result->pixels[(x + (result->height - y - 1) * result->width)*4 + 2];
u8 A = result->pixels[(x + (result->height - y - 1) * result->width)*4 + 3];
u32 color = B + G*256 + R*256*256;
DrawAlphaPixel(buffer,xp+x,yp+y,color,A);
}
}
}
}

Code:
void DrawPixel(u8* screen, int x,int y, u32 color){
int idx = ((x)*240) + (239-(y));
screen[idx*3+0] = (color);
screen[idx*3+1] = (color) >> 8;
screen[idx*3+2] = (color) >> 16;
}
 
But, for some reason, i don't get a square, i got 5 vertical lines above each other of 5-6 pixels width, and it is flickering really fast.

Why your putpixel func writes 3 u8 memory locations if your color is only u16 (i.e. u8 x 2) ? ;)
 
Why your putpixel func writes 3 u8 memory locations if your color is only u16 (i.e. u8 x 2) ? ;)

Have no idea, but it works, the flickering was because i kept calling gfxFlushBuffers(); and gfxSwapBuffers();
 
Code:
static inline void putPixel565(u8* dst, u8 x, u8 y, u16 v)
{
dst[(x+(47-y)*48)*3+0]=(v&0x1F)<<3;
dst[(x+(47-y)*48)*3+1]=((v>>5)&0x3F)<<2;
dst[(x+(47-y)*48)*3+2]=((v>>11)&0x1F)<<3;
}


you gave this function to me about writing RGB565 colors to the screen.
I'm not entirely sure, but i believe that u8 has a maximum value of 255.

So if you would want to write something after x value 255, and passes it to this function, you will get an overflow, and it won't get the correct position.
While using this i function i couldn't write past x value 255, after changing the function arguments to int, this did worked for me.

As I said, i'm not sure, but this fixed the problem for me, just thought to let you know.
 
  • Like
Reactions: Rinnegatamante
you gave this function to me about writing RGB565 colors to the screen.
I'm not entirely sure, but i believe that u8 has a maximum value of 255.

So if you would want to write something after x value 255, and passes it to this function, you will get an overflow, and it won't get the correct position.
While using this i function i couldn't write past x value 255, after changing the function arguments to int, this did worked for me.

As I said, i'm not sure, but this fixed the problem for me, just thought to let you know.

You're right, thanks for your feedback, i'll fix it immediately :)

Does someone knows how to interact with a PHP script?
I'm just trying to do something with GET method but i get a console freeze (probably related to while (loading != 0x7):

Code:
static int lua_sendmail(lua_State *L){ //BETA func
    int argc = lua_gettop(L);
    if (argc != 3) return luaL_error(L, "wrong number of arguments");
    const char* to = luaL_checkstring(L,1);
    const char* subj = luaL_checkstring(L,2);
    const char* mex = luaL_checkstring(L,3);
    char* url = (char*)malloc(strlen(to)+strlen(subj)+strlen(mex)+100);
    strcpy(url,"http://rinnegatamante.netsons.org/my_test_script.php?t=");
    strcat(url,to);
    strcat(url,"&s=");
    strcat(url,subj);
    strcat(url,"&b=");
    strcat(url,mex);
    httpcContext context;
    Result ret = httpcOpenContext(&context, (char*)url , 0);
    if(ret==0){
        httpcBeginRequest(&context);
        httpcReqStatus loading;
        httpcGetRequestState(&context, &loading);
        while (loading != 0x7){
            httpcGetRequestState(&context, &loading);
        }
        u32 statuscode=0;
        u32 contentsize=0;
        httpcGetResponseStatusCode(&context, &statuscode, 0);
        if (statuscode != 200) luaL_error(L, "request error");
        httpcGetDownloadSizeState(&context, NULL, &contentsize);
        u8 response;
        httpcDownloadData(&context, &response, contentsize, NULL);
        lua_pushboolean(L,response);
        free(url);
    }else luaL_error(L, "error opening url");
    httpcCloseContext(&context);
    return 1;
}
 
You're right, thanks for your feedback, i'll fix it immediately :)

Does someone knows how to interact with a PHP script?
I'm just trying to do something with GET method but i get a console freeze (probably related to while (loading != 0x7):

Code:
static int lua_sendmail(lua_State *L){ //BETA func
    int argc = lua_gettop(L);
    if (argc != 3) return luaL_error(L, "wrong number of arguments");
    const char* to = luaL_checkstring(L,1);
    const char* subj = luaL_checkstring(L,2);
    const char* mex = luaL_checkstring(L,3);
    char* url = (char*)malloc(strlen(to)+strlen(subj)+strlen(mex)+100);
    strcpy(url,"http://rinnegatamante.netsons.org/my_test_script.php?t=");
    strcat(url,to);
    strcat(url,"&s=");
    strcat(url,subj);
    strcat(url,"&b=");
    strcat(url,mex);
    httpcContext context;
    Result ret = httpcOpenContext(&context, (char*)url , 0);
    if(ret==0){
        httpcBeginRequest(&context);
        httpcReqStatus loading;
        httpcGetRequestState(&context, &loading);
        while (loading != 0x7){
            httpcGetRequestState(&context, &loading);
        }
        u32 statuscode=0;
        u32 contentsize=0;
        httpcGetResponseStatusCode(&context, &statuscode, 0);
        if (statuscode != 200) luaL_error(L, "request error");
        httpcGetDownloadSizeState(&context, NULL, &contentsize);
        u8 response;
        httpcDownloadData(&context, &response, contentsize, NULL);
        lua_pushboolean(L,response);
        free(url);
    }else luaL_error(L, "error opening url");
    httpcCloseContext(&context);
    return 1;
}

This probably isn't it, but when i go to the link i get a 404.
What request state stands 0x7 for?
 
You're right, thanks for your feedback, i'll fix it immediately :)

Does someone knows how to interact with a PHP script?
I'm just trying to do something with GET method but i get a console freeze (probably related to while (loading != 0x7):

Code:
static int lua_sendmail(lua_State *L){ //BETA func
    int argc = lua_gettop(L);
    if (argc != 3) return luaL_error(L, "wrong number of arguments");
    const char* to = luaL_checkstring(L,1);
    const char* subj = luaL_checkstring(L,2);
    const char* mex = luaL_checkstring(L,3);
    char* url = (char*)malloc(strlen(to)+strlen(subj)+strlen(mex)+100);
    strcpy(url,"http://rinnegatamante.netsons.org/my_test_script.php?t=");
    strcat(url,to);
    strcat(url,"&s=");
    strcat(url,subj);
    strcat(url,"&b=");
    strcat(url,mex);
    httpcContext context;
    Result ret = httpcOpenContext(&context, (char*)url , 0);
    if(ret==0){
        httpcBeginRequest(&context);
        httpcReqStatus loading;
        httpcGetRequestState(&context, &loading);
        while (loading != 0x7){
            httpcGetRequestState(&context, &loading);
        }
        u32 statuscode=0;
        u32 contentsize=0;
        httpcGetResponseStatusCode(&context, &statuscode, 0);
        if (statuscode != 200) luaL_error(L, "request error");
        httpcGetDownloadSizeState(&context, NULL, &contentsize);
        u8 response;
        httpcDownloadData(&context, &response, contentsize, NULL);
        lua_pushboolean(L,response);
        free(url);
    }else luaL_error(L, "error opening url");
    httpcCloseContext(&context);
    return 1;
}

Try this:
Code:
while (loading != 0x7 && loading == 0x5){
  httpcGetRequestState(&context, &loading);
}
if(loading != 7) {
  //something wrong, but not with your code
}

I'm guessing that, (if the file is online), you get a error 403.
Browsers normally redirect an 403 automatically, but C doesn't.
 
Is it possible to launch a cartridge with the APT Services?

I don't know but is possible with ns:s service for example lpp-3ds provides a function to launch retail cartridges with this:
Code:
static int lua_startcard(lua_State *L) {
int argc = lua_gettop(L);
if(argc != 0 ) return luaL_error(L, "wrong number of arguments.");
srvGetServiceHandle(&nsHandle, "ns:s");
NS_RebootToTitle(mediatype_GAMECARD,0);
svcCloseHandle(nsHandle);
return 0;
}
 

Site & Scene News

Popular threads in this forum