Tutorial DS Programming for Newbies!

  • Thread starter Foxi4
  • Start date
  • Views 154,310
  • Replies 323
  • Likes 55

Dani24f

Member
Newcomer
Joined
Apr 20, 2020
Messages
13
Trophies
0
XP
240
Country
Italy
I'm not exactly sure how these libraries work but don't you need to create your own struct object with that type first?
The struct object is inside the system.h file, trying to declare it gives me an "already declared inside file system.h"-sort of error.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
28,406
Trophies
2
Location
Gaming Grotto
XP
25,856
Country
Poland
Yes, I tried using it as a normal variable too
I suggest using time.h instead and getting seconds as such:

secs = timeStruct->tm_sec;

Relevant libnds example:
https://github.com/devkitPro/nds-examples/blob/master/time/RealTimeClock/source/main.c

You may be able to use the built-in RTC function in the same way, but at this stage I have no idea what does or doesn't work as expected in libnds, so I tend to go by what libnds creators themselves suggest.

Structure reference:
http://www.cplusplus.com/reference/ctime/tm/

I'm not at my PC right now so I can't compile on my end, but when in doubt, standardised functions come to the rescue.

EDIT: Did this resolve your issue @Dani24f, or should I start up my PC and look at your source? I'm back at my workstation if you need a hand.
 

Dani24f

Member
Newcomer
Joined
Apr 20, 2020
Messages
13
Trophies
0
XP
240
Country
Italy
I suggest using time.h instead and getting seconds as such:

secs = timeStruct->tm_sec;

Relevant libnds example:
https://github.com/devkitPro/nds-examples/blob/master/time/RealTimeClock/source/main.c

You may be able to use the built-in RTC function in the same way, but at this stage I have no idea what does or doesn't work as expected in libnds, so I tend to go by what libnds creators themselves suggest.

Structure reference:
http://www.cplusplus.com/reference/ctime/tm/

I'm not at my PC right now so I can't compile on my end, but when in doubt, standardised functions come to the rescue.

EDIT: Did this resolve your issue @Dani24f, or should I start up my PC and look at your source? I'm back at my workstation if you need a hand.
Hi, I tried using time.h as you said, but I get a "'timeStruct' was not declared in this scope" error.

Here's my code, so you check it out (thanks for helping me btw!):
Code:
#include <nds.h>
#include <stdio.h>
#include <time.h>

u8 secs=0;
float fps=0;


int main(){
    consoleDemoInit();
    while(1){
        printf("Initializing..."); /*This displays while waiting for the first second to pass*/
        fps = fps + 1; /*This increases the fps counter every frame*/
        secs = timeStruct->tm_sec; /*This gives a "timeStruct' was not declared in this scope" error when compiling*/
        if (( timeStruct->tm_sec - secs ) == 1 ) { /*If a second is passed*/
            iprintf("\rHello world by Dani24f! FPS: %.2f ", fps);
            fps = 0; /*Resets the fps variable and waits for another second to display the current fps*/
            if ( secs == 58 ) { secs = 0; } /*This prevents any error in the subtraction tm_sec - secs*/
        }
        swiWaitForVBlank();  
    }
}
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
28,406
Trophies
2
Location
Gaming Grotto
XP
25,856
Country
Poland
Hi, I tried using time.h as you said, but I get a "'timeStruct' was not declared in this scope" error.

Here's my code, so you check it out (thanks for helping me btw!):
Code:
#include <nds.h>
#include <stdio.h>
#include <time.h>

u8 secs=0;
float fps=0;


int main(){
    consoleDemoInit();
    while(1){
        printf("Initializing..."); /*This displays while waiting for the first second to pass*/
        fps = fps + 1; /*This increases the fps counter every frame*/
        secs = timeStruct->tm_sec; /*This gives a "timeStruct' was not declared in this scope" error when compiling*/
        if (( timeStruct->tm_sec - secs ) == 1 ) { /*If a second is passed*/
            iprintf("\rHello world by Dani24f! FPS: %.2f ", fps);
            fps = 0; /*Resets the fps variable and waits for another second to display the current fps*/
            if ( secs == 58 ) { secs = 0; } /*This prevents any error in the subtraction tm_sec - secs*/
        }
        swiWaitForVBlank();
    }
}
You need a timeStruct first. :P

time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);

This will create a time structure "tm" in UTC format. Admittedly a bit overcomplicated, this would be used for something like a clock, so I'll see if it can done in a simpler way (it can be). Honestly, you should be able to get framerate by comparing CPU ticks vs. screen refreshes with acceptable accuracy.
 

SkilLP

Active Member
Newcomer
Joined
May 2, 2020
Messages
28
Trophies
0
XP
278
Country
Germany
Thanks for this awesome guide! I wanted to start making NDS homebrew a while back, but I just didn't know where to look for a guide or sth like that, but about 2 months ago, PolyMars led me here. Nice work!
 
  • Like
Reactions: PolyMars

SkilLP

Active Member
Newcomer
Joined
May 2, 2020
Messages
28
Trophies
0
XP
278
Country
Germany
I have a question: As you may know, updating too many sprites while also having the DS calculate a lot can lead to sprites not getting properly deleted and staying on the screen even in the same position even after moving or even deleting. They don't do anything there, they just don't do anything. I had that problem when I made a game where you had to dodge falling meteors and the only way around that issue was deleting those sprites after they were off screen so you couldn't see the artifacts. Do you know how to fix this?
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
28,406
Trophies
2
Location
Gaming Grotto
XP
25,856
Country
Poland
I have a question: As you may know, updating too many sprites while also having the DS calculate a lot can lead to sprites not getting properly deleted and staying on the screen even in the same position even after moving or even deleting. They don't do anything there, they just don't do anything. I had that problem when I made a game where you had to dodge falling meteors and the only way around that issue was deleting those sprites after they were off screen so you couldn't see the artifacts. Do you know how to fix this?
This shouldn't be the case, once you refresh the screen they should be gone. Can you provide a snippet?
 

SkilLP

Active Member
Newcomer
Joined
May 2, 2020
Messages
28
Trophies
0
XP
278
Country
Germany
This shouldn't be the case, once you refresh the screen they should be gone. Can you provide a snippet?
I'm not sure what you mean, but if you mean what my update looks like, here it is:
Code:
NF_SpriteOamSet(0);
NF_ResetSpriteBuffers();
swiWaitForVBlank();
oamUpdate(&oamMain);
I may have misunderstood the question though
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
28,406
Trophies
2
Location
Gaming Grotto
XP
25,856
Country
Poland
I'm not sure what you mean, but if you mean what my update looks like, here it is:
Code:
NF_SpriteOamSet(0);
NF_ResetSpriteBuffers();
swiWaitForVBlank();
oamUpdate(&oamMain);
I may have misunderstood the question though
The maximum number of sprites the DS can handle is pre-set - if they stay on the screen after being destroyed/deleted one of a couple of things might be happening - you've created more than the maximum number allowed (NFLib should stop you from doing that, so it's unlikely), you've overflown some kind of buffer or the DS is unable to properly refresh for some reason. It shouldn't display anything that's not actively loaded and within the bounds of the screen, so there's an error somewhere along the line. Your screen update routine is correct, but I would review everything else as this should not be happening.

A good way to test this is to create a test environment. Isolate all the code relating to sprite generation, set one button to create a new sprite and one to destroy the last one you've made, and keep creating them until the error triggers - that will help you narrow things down.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
28,406
Trophies
2
Location
Gaming Grotto
XP
25,856
Country
Poland
You will also see graphical glitches like this if you send more data into the screen buffer than the screen can handle, but normally NFLib handles that automatically as long as you refresh it at the end of the loop, if there are any errors in this regard it should dump them into the console, which you should be able to pull up.
 

Arrie

New Member
Newbie
Joined
May 12, 2020
Messages
2
Trophies
0
Age
22
XP
18
Country
Netherlands
This link doesn't work anymore and it's also not in the wayback machine's web archive.

pern . drunkencoders . com /download-wiz
 
Last edited by Arrie,

Arrie

New Member
Newbie
Joined
May 12, 2020
Messages
2
Trophies
0
Age
22
XP
18
Country
Netherlands
Oh, thanks for the quick reply! Also, I was wondering, is this still the most up-to-date tutorial? Since it's from 2012..
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
28,406
Trophies
2
Location
Gaming Grotto
XP
25,856
Country
Poland
Oh, thanks for the quick reply! Also, I was wondering, is this still the most up-to-date tutorial? Since it's from 2012..
Well, nothing concerning DS development is really up-to-date since the platform was phased out, but the guide was written at the tail end of the life cycle, not to mention that the coding concepts are applicable regardless of the platform - C is C. Just keep in mind that many links might be dead and I have no backups of the software, so you may have to get creative sometimes. The forum has migrated since this was posted as well and I did my best to clean up the code since, but some fragments may be poorly formatted. Still, if you read thoroughly, you'll figure it out. :)
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
28,406
Trophies
2
Location
Gaming Grotto
XP
25,856
Country
Poland
I'm very new to libnds and I'm not sure how to compile my code with programmer's notepad
You should be able to find a template inside the devkitPro folder - save your code as the main file and then go to Tools - - > Make in PN. There are various templates available depending on what hardware you need to use, but if you're a newbie, you can just grab the Hello World example and start from there. :)
 
  • Like
Reactions: PolyMars
General chit-chat
Help Users
  • godreborn @ godreborn:
    I have like 40 minutes in the game, trying to escape this one safe house after it being attacked.
    Gift
  • godreborn @ godreborn:
    it's different. you get no gald in battles, and it shows your experience and stuff in the field map after each battle, so there's no battle poses or anything, which I miss.
    Gift
  • AncientBoi @ AncientBoi:
    O geez, I've been looking for my character in Ghost Recon
    Gift
  • AncientBoi @ AncientBoi:
    forgot it's FPS and not a TPS
    Gift
  • AncientBoi @ AncientBoi:
    <=== DUMMY
    +1
    Gift
  • godreborn @ godreborn:
    lol, Hayato said he liked arise more than vesperia. I'm a ways in vesperia, have the flying vehicle or whatever it is actually in that, so it will take a lot for me to feel the same way. I need to go through the fire temple in oot via nso on the switch. I'm in the first room. I was going to go through it this morning, but I way overslept.
    Gift
  • Gift
  • godreborn @ godreborn:
    can't walk in a straight line very well with the analog stick of the n64 controller in zelda. the analog stick on the ps5 controller is extremely comfortable by comparison though.
    Gift
  • AncientBoi @ AncientBoi:
    I fixed my cheap Logitech controller. Character moves forward now. YaY
    +1
    Gift
  • AncientBoi @ AncientBoi:
    And my PPSSPP Emulator is running a bit smooother. YaY
    Gift
  • godreborn @ godreborn:
    I kicked dkc returns ass just now. 99 lives, all kong letters, all stages, 0 deaths at 5-7 beaten
    +1
    Gift
  • Gift
  • Gift
  • godreborn @ godreborn:
    that 5-7 is a doozy. that's when my doctor thought I had Parkinson's. the day he thought that, I dropped the controller multiple times while playing through it.
    Gift
  • AncientBoi @ AncientBoi:
    [uploads butt hurt cream for dkc returns]
    Gift
  • Gift
  • godreborn @ godreborn:
    about to play tropical freeze. I play new games in the mornings, then my comfort games while trying to help others or chat in the afternoons.
    Gift
  • AncientBoi @ AncientBoi:
    I'm an FPS game fan.
    Gift
  • AncientBoi @ AncientBoi:
    and flying simulators
    now n then
    Gift
  • godreborn @ godreborn:
    I have a hard time aiming in games like fps unless there's a lock on. I beat the sling shot and bow and arrow mini games in oot, and they were hard without lock on.
    Gift
  • AncientBoi @ AncientBoi:
    true true. I tend to take off the locks on's
    Gift
  • AncientBoi @ AncientBoi:
    <=== Love being a sniper type
    Gift
  • godreborn @ godreborn:
    lol, shoot the guy in the balls or the head?
    Gift
  • AncientBoi @ AncientBoi:
    uh... guilty
    Gift
  • AncientBoi @ AncientBoi:
    hehehehe
    Gift
    AncientBoi @ AncientBoi: hehehehe