a technical look at PAlib_BgTrans and then trying to implement it on NFlib.

aerglass

Well-Known Member
OP
Member
Joined
Apr 10, 2022
Messages
186
Trophies
0
Location
Fever Dream Zone
XP
592
Country
Venezuela
Welcome to another episode of torturing myself for something that absolutely nobody has asked for.
I have been working on PA2lib PAlib sprite backwards compatibility, it has been painful and it still does not work tho. whatever nobody cares.


After wasting 80+ hours on the PAlib source code to see something that can help me on implementing sprite support onto PA2lib I remembered about PAlib's Bg Transition function, some people thinked this was bloatware, i found this useful on the past, that is why a customized version of PAlib (That does not have sh** like mode7 or PA_Nothing that makes me die of cringe.) is my main lib for creating nds stuff (plz do not kill me i just think it is better for me, i already tested NFlib and i didn't liked it.). Ok so at the time i was recreating my proyects on NFlib because i wanted to switch to NFlib (instant regret lol) and i got this crazy idea about implementing PAlib's bgtrans functions onto NFlib code, before you start dming me, in some ways PA2lib is renamed nflib (first version was almost NFlib with some changes) and if i implement this onto nflib it will be easy to implement it onto PA2lib + NFlib is more used and recommended than PA2lib so why not? It ended up wrong lol. I mean displaying corrupted graphics on the DS screen is already my job.

Here is the story if you wanna for some reason make the same thing.

1. A look at PAlib source code to understand.

if you ask me "how does PAlib bg transition stuff work?" I would normally respond "its just bg tilemap changing and that is it" but today i am gonna explain it all.

PAlib integrates some image called "PA_TransBg.png" and it has all the types of bgs that PAlib uses. It converts it using PAGfx and it is integrated onto the main lib.
onto the file (palib1007directory/source/PA_BgTrans.c there is the source for transbg i guess.
C:
#include <PA9.h>

#include "TransBg/all_gfx.h"

u8 pa_bg_trans[2];

void PA_InitBgTransEx(u8 screen, u8 bg) {
    pa_bg_trans[screen] = bg;
    PA_LoadBackground(screen, bg, &PA_TransBg);
    PA_BgTransUpDown(screen, 0, 0, TRANS_LENGTH); // Hide
}
whatever that files include the all_gfx of transbg which means that the transformed bg is being used.
C:
void PA_BgTransTile(u8 screen, u16 type, s16 x, s16 y, s16 temptile) {
    u16* map = (u16*) PA_TransBg.BgMap;
    PA_SetMapTileAll(screen, pa_bg_trans[screen], x, y, map[temptile*2+type]);
    PA_SetMapTileAll(screen, pa_bg_trans[screen], x + 1, y, map[temptile*2+1+type]);
    PA_SetMapTileAll(screen, pa_bg_trans[screen], x, y + 1, map[temptile*2+32+type]);
    PA_SetMapTileAll(screen, pa_bg_trans[screen], x + 1, y + 1, map[temptile*2+1+32+type]);
}

void PA_BgTransUpDown(u8 screen, u16 type, u8 vflip, s16 state) {
    int i, j;
    s16 tile = state >> 1;
    s16 temptile;
    int y;
    type = type << 6;
    int x;

    for (j = 0; j < 12; j++) {
        y = j * 2;

        if (vflip) y = (11 - j) * 2;

        temptile = tile;

        if (temptile > 15) temptile = 15; // limit range...

        for (i = 0; i < 16; i++) {
            x = i * 2;
            PA_BgTransTile(screen, type, x, y, temptile);
        }

        if (tile) tile--;
    }
}
If you know full libnds and PAlib then you understand, if you do not then basically, PA_BgTransTile is PA_SetMapTile which is modifying the current bg map. PA_BgTransUpDown basically uses that function to swap the current tiles, to a certain velocity so that it becomes a transation. there you go, if you don't understand or think that what i am saying is wrong please say it to me, i am not the best at explaining things.


2.Implementing it onto NFlib

I can't say anything but it does not work and it needs the PA_BgTrans.png file extracted from the PAlib source code. I found it under a customized version on NFlib because i do not like vanilla NFlib
C:
#include <stdio.h>
#include <nds.h>
#include <nf_lib.h>

u8 pa_bg_trans[2];

void PA_BgTransTile(u8 screen, u16 type, s16 x, s16 y, s16 temptile) {
    //i tried doing a for loop on here so that all y tiles are replaced and that didn't work so i insted let it like this
    NF_SetTileOfMap(screen, 0,x, 0,pa_bg_trans[0]);
}

void PA_BgTransUpDown(u8 screen, u16 type, u8 vflip, s16 state) {
    int i, j;
    s16 tile = state >> 1;
    s16 temptile;
    int y;
    type = type << 6;
    int x;

    for (j = 0; j < 12; j++) {
        y = j * 2;

        if (vflip) y = (11 - j) * 2;

        temptile = tile;

        if (temptile > 15) temptile = 15; // limit range...

        for (i = 0; i < 16; i++) {
            x = i * 2;
            PA_BgTransTile(screen, 0, x, y, temptile);
        }

        if (tile) tile--;
    }
}


void PA_InitBgTransEx(u8 screen, u8 bg) {
    pa_bg_trans[screen] = bg;
    NF_LoadTiledBg("PA_TransBg", "tras", 256,256);
    NF_CreateTiledBg(0,0,"tras");
    PA_BgTransUpDown(0, 0, 0, 70); // Hide
}

int main(int argc, char **argv) {
    NF_Set2D(0, 0);
    NF_Set2D(1, 0);  
    consoleDemoInit();
    iprintf("\n NitroFS init. Please wait.\n\n");
    iprintf(" Iniciando NitroFS,\n por favor, espere.\n\n");
    swiWaitForVBlank();

    NF_SetRootFolder("NITROFS");  

    NF_Set2D(0, 0);              
    NF_Set2D(1, 0);
    s32 i = 0;
    NF_InitTiledBgBuffers();  
    NF_InitTiledBgSys(0);      
    NF_InitTiledBgSys(1);
    NF_LoadTiledBg("nfl", "nfl", 256, 256);
    NF_CreateTiledBg(0, 3, "nfl");
    PA_InitBgTransEx(0,0);

    s32 height = 0;
    for (i = 32; i >= 0; i--) {
        PA_BgTransUpDown(0,0,0,i);
        NF_UpdateVramMap(0,0);
        swiWaitForVBlank();
    }
    while(1){
        swiWaitForVBlank();
    }
    return 0;
}
now goodbye, i already tortured myself enough. pa2lib is probably gonna get discontinued because of time and school.
edit: i am not asking for help, this is just if someone ever needs this
 
  • Like
Reactions: YuseiFD
General chit-chat
Help Users
  • SylverReZ @ SylverReZ:
    Hope they made lots of spaget
  • K3N1 @ K3N1:
    Chill dog
  • SylverReZ @ SylverReZ:
    Chilli dog
  • Skelletonike @ Skelletonike:
    Damn, I'm loving the new zelda.
  • xtremegamer @ xtremegamer:
    loving the new zelda, i started a game, it was so fucking good, so i
    am waiting on my friend to get home so we can start a new one together
  • Skelletonike @ Skelletonike:
    I just dislike that they don't let me choose the voices before the game starts. Happened with botw as well, had to change to japanese and restart.
  • K3N1 @ K3N1:
    But the important question is can you choose gender
  • Skelletonike @ Skelletonike:
    Same way you can choose Gerald's gender.
  • Skelletonike @ Skelletonike:
    *Geralt, damn autocorrect.
  • Psionic Roshambo @ Psionic Roshambo:
    But can he be trans? Lol
  • K3N1 @ K3N1:
    Zelda transforms into link
  • Psionic Roshambo @ Psionic Roshambo:
    Link I'm not the princess your looking for.... *Pulls a crying game*
  • K3N1 @ K3N1:
    *skirt up* it's exactly what I always wanted
  • Skelletonike @ Skelletonike:
    Just scanned all my zelda amiibos, took a while but didn't get anything that cool, did get the lon lon ranch hylian fabrics though.
  • Skelletonike @ Skelletonike:
    It was pretty funny when I scanned wolf link and got a shit load of meat.
  • K3N1 @ K3N1:
    @Skelletonike, btw I ran that custom for mgs4 on the deck I'm amazed it got that far in game
  • K3N1 @ K3N1:
    Plug in*
  • K3N1 @ K3N1:
    Your favorite activity
  • BentlyMods @ BentlyMods:
    My fav actvity is:

    mario-dancing.gif
  • Psionic Roshambo @ Psionic Roshambo:
    Do the Mario lol
  • K3N1 @ K3N1:
    🍑
    K3N1 @ K3N1: 🍑