Pages: 1
Posted on 08-22-11, 01:04 am
Roy Koopa


Karma: 4011
Posts: 472/2722
Since: 06-26-11
Is there a wait command for libnds? sleep(x) and wait(x) does not work
_________________________
See a lots of creative DS Hacking here
If you want to support me, you might check out my Patreon Page : )
Posted on 08-22-11, 05:40 am
Porcupo
Did you win the game?

Karma: 211
Posts: 72/322
Since: 06-28-11
...
No not quite but it is VEEEERRRRYYY easy to make your own.


Basic Way:
The DS runs at 60 frames per second right? (You should really know this.)
swiWaitForVBlank waits for the next frame.

so to wait one second we should call swiWaitForVBlank(); 60 times
like so:


Another way is the read the time until the difference of the time is 1 second.
I can not remember the code for this now from memory.
I do know that it would be something like: (note that you have to include the time.h file for this one)

while(1){
double x,y;
x=1;
//Something goes in here
y=difftime(&la,&blah);
if (x==y) break;
}
Posted on 08-22-11, 01:09 pm
Super Mario
( ͡° ͜ʖ ͡°)

Karma: 10010
Posts: 679/4457
Since: 06-08-11
Yeah. The first one is actually better, because it puts the CPU to sleep mode waiting for the next VBlank so it reduces power consumption.

The second one is constantly looping. And be careful with doubles. I'd change x==y to x<=y.

Comparing doubles with == can be a bad idea. One example is:

if(0.1+0.1+0.1 == 0.3) printf("yes\n");
else printf("no\n");

That code prints NO. Yeah, try it. It's because of precision errors.
Posted on 08-23-11, 01:05 am (rev. 1)
Roy Koopa


Karma: 4011
Posts: 474/2722
Since: 06-26-11
Yeah thank you. I choosed the first one and it worked ^.^ Of course, I know the DS runs at 60 FPS

EDIT: I'm trying to increase a number every second. I have a variable "int e;" and set it to 0 "e = 0;". Then I use cool as method to increase it every second:

if (i = true)
for (count=0;count<=60;count++)
swiWaitForVBlank;
printf(e);
e++;

But instead of printing numbers (1, 2, 3....99999) it prints smilies and other weird things o0 Can someone help me?
_________________________
See a lots of creative DS Hacking here
If you want to support me, you might check out my Patreon Page : )
Posted on 08-23-11, 04:48 am
Porcupo
Did you win the game?

Karma: 211
Posts: 75/322
Since: 06-28-11
oOoO .......
printf has the arguments:
int printf ( const char * format, ... ); //From www.cplusplus.com

Instead of giving it a const char *. Ray you are giving it an Int. (int e; I assume)
You need to do this:

printf("%d",e);

The "" creates a const char *.
The %d tells The ds (or compiler) that the next argument is a decimal number and that you would like to print it.

The next argument is a int which is a decimal number.

Before the DS was thinking that the int e was actually a char and printing the ASCII representation of it.

It would print out the ASCII table letter by letter.
www.asciitable.com
Posted on 08-23-11, 05:38 pm (rev. 1)
Roy Koopa


Karma: 4011
Posts: 476/2722
Since: 06-26-11
Ok thanky you
EDIT:
Can anyone tell me, why i is set to true when I start the rom? Here's my code

if(REG_KEYINPUT & KEY_A)
i = false;
else
i = true;
if (i = true)
for (count=0;count<=60;count++)
swiWaitForVBlank();
printf("%d\n",e);
e++;

So usually i have to be false (beacuse I dont press A) and when I press A it should be true. But when I start the rom, it writes the numbers Why?
_________________________
See a lots of creative DS Hacking here
If you want to support me, you might check out my Patreon Page : )
Posted on 08-23-11, 07:06 pm
Super Mario
( ͡° ͜ʖ ͡°)

Karma: 10010
Posts: 692/4457
Since: 06-08-11
Because REG_KEYINPUT works the opposite way: the bit is 1 when the button is not pressed.

Anyways, you should use the library functions to read keys. scanKeys(), keysDown(), keysHeld(), etc. Look them up on the documentation, or in the examples
Posted on 08-23-11, 07:18 pm
Roy Koopa


Karma: 4011
Posts: 481/2722
Since: 06-26-11
I tried the opposite and it didnt worked I also tried it with keysheld.. but didnt worked either
_________________________
See a lots of creative DS Hacking here
If you want to support me, you might check out my Patreon Page : )
Posted on 08-23-11, 07:19 pm
Super Mario
( ͡° ͜ʖ ͡°)

Karma: 10010
Posts: 694/4457
Since: 06-08-11
Oooh, there's another bug


if (i = true)

should be

if (i == true)

ALWAYS use == to compare. One = just assigns a value to the variable.
Posted on 08-23-11, 07:34 pm (rev. 1 by ImageBot on 11-21-16, 02:08 am)
Roy Koopa


Karma: 4011
Posts: 482/2722
Since: 06-26-11
Thanks dirbaio and thanks Cool As. With Your help I could finish my first own (usefull xD) homebrew Nothing special but for me as a beginner its nice Doesnt support miliseconds

Download
_________________________
See a lots of creative DS Hacking here
If you want to support me, you might check out my Patreon Page : )
Pages: 1