#159839 - ragefury32 - Mon Jul 07, 2008 11:19 am
Okay, so I am trying to do some development on DSWifi, and I am looking into the wifi-example1 - I modified it so it runs in a loop, running Wifi_AutoConnect until it works, and then doing the socket build-out/results print. But here's the thing...it's also sitting inside an infinite loop, so on a success connect, the text will print out and then disappear, and then run back to the top. Is there a way to run usleep() or sleep()? I found out that for some reason, devKitPro does not seem to allow me to link to it during the compile process.
#159843 - fluff - Mon Jul 07, 2008 11:36 am
I think the closest you can get is the swiDelay(x) call. x doesn't correspond to any human time values, but rather #iterations through a tight little loop as I understand it. I don't know exactly how those relate to say ms, but look it up or experiment!
There's also swiWaitForVBlank(), but that's obviously accurate to worse than 1/60s and you have to have IRQ_VBLANK enabled. On the upside though, the cpu doesn't waste power while in there.
#159868 - Lazy1 - Mon Jul 07, 2008 8:52 pm
I think you can also set up a timer to fire an irq and use the wait for interrupt swi.
gbatek wrote: |
SWI 04h (GBA/NDS7/NDS9) - IntrWait
Continues to wait in Halt state until one (or more) of the specified interrupt(s) do occur. The function forcefully sets IME=1. When using multiple interrupts at the same time, this function is having less overhead than repeatedly calling the Halt function.
r0 0=Return immediately if an old flag was already set (NDS9: bugged!)
1=Discard old flags, wait until a NEW flag becomes set
r1 Interrupt flag(s) to wait for (same format as IE/IF registers)
Caution: When using IntrWait or VBlankIntrWait, the user interrupt handler MUST update the BIOS Interrupt Flags value in RAM; when acknowleding processed interrupt(s) by writing a value to the IF register, the same value should be also ORed to the BIOS Interrupt Flags value, at following memory location:
Host GBA (16bit) NDS7 (32bit) NDS9 (32bit)
Address [3007FF8h] [380FFF8h] [DTCM+3FF8h]
NDS9: BUG: No Discard (r0=0) doesn't work. The function always waits for at least one IRQ to occur (no matter which, including IRQs that are not selected in r1), even if the desired flag was already set. NB. the same bug is also found in the GBA/NDS7 functions, but it's compensated by a second bug, ie. the GBA/NDS7 functions are working okay because their "bug doesn't work".
Return: No return value, the selected flag(s) are automatically reset in BIOS Interrupt Flags value in RAM upon return.
|
#159870 - josath - Mon Jul 07, 2008 9:04 pm
microsecond accuracy? interrupts? I think this is all too complicated if your goal is simply to stop text from scrolling off the screen too quickly. How about this: when the screen fills up, don't print any more until the user presses a key, perhaps A or DOWN or something.
#160369 - ragefury32 - Mon Jul 14, 2008 4:32 pm
josath wrote: |
microsecond accuracy? interrupts? I think this is all too complicated if your goal is simply to stop text from scrolling off the screen too quickly. How about this: when the screen fills up, don't print any more until the user presses a key, perhaps A or DOWN or something. |
Using what? getChar() doesn't exactly work, and scankey() is non-blocking.
#160371 - silent_code - Mon Jul 14, 2008 4:54 pm
Code: |
while((REG_KEYINPUT & KEY_A) && (REG_KEYINPUT & KEY_START))
{
swiWaitForVBlank();
}
|
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#160386 - josath - Mon Jul 14, 2008 11:03 pm
I'd probably do something like:
Code: |
scanKeys();
while(!(keysHeld() & (KEY_A | KEY_START))) {
scanKeys();
swiWaitForVBlank();
} |
I like using the libnds keysHeld()/keysDown()/keysUp() functions better than reading the key register directly. The extra scanKeys() outside the loop is there just to prevent previous button presses from getting caught...you may not need it depending how your code is structured.