Jump to content

VBlank detection using SWI calls


Recommended Posts

Hi folks,

Well I finally got my passme board up and working IIIEEEEEE ;)

And my demo's coming along nicely...

 

However I've noticed a little problem.

 

Reading the touchpad (using the ARM7 to fill in the IPC struct as specified in the NDSLIB stuff) only returns sporadic results, I've traced this down to the fact that when my ARM9 main loop is basically doing nothing but waiting for a VBLANK it sits in a tight loop checking the VCOUNT register.

 

This is fine for the ARM9 except that this causes (I believe) the ARM9 to hog all the memory bandwidth, thus not allowing the ARM7 to fill in the IPC data - In fact the only time I get results is when I occasionally change the contents of VRAM (thus freeing up main memory access) - hence the sporadic nature of the pen.

 

The obvious anwser seems to be to use the swiWaitForVBlank() call in NDSLib (as this works fine on ARM7), however it seems to be broken in ARM 9, the source "looks" ok, but there are comments to this effect in some of the Demos (plus it creashes my app, so it must be true :( )

 

Does anybody have any ideas (or a fixed swiWaitForVBlank() function).

 

FWIW - I've tried changing the main memory priority flag in the WAIT_CR register, but this didn't seem to have any effect...

 

As usual, all help and advice greatfully recieved.

 

Cheeers

 

The BillMeister...

Link to comment
Share on other sites

The best solution would probably be to have the ARM7 code running from its own dedicated RAM. I don't know if this has been done by the people who are working on the linker scripts and C runtime (mainly WntrMute).

As far as the SWI goes, I know it was broken in the past in NDSLIB. I haven't checked out the last couple of versions so I can't tell you if they've fixed it yet.

Link to comment
Share on other sites

  • 2 months later...
The obvious anwser seems to be to use the swiWaitForVBlank() call in NDSLib (as this works fine on ARM7), however it seems to be broken in ARM 9, the source "looks" ok, but there are comments to this effect in some of the Demos (plus it creashes my app, so it must be true  :D )

 

Does anybody have any ideas (or a fixed swiWaitForVBlank() function).

 

It seems to work OK for me... Have you enabled VBlank interupts? They need to be enabled for swiWaitForVBlank to work otherwise it will simply hangs. This behaviour occurs on the real hardware too.

 

I hope this was the issue.

 

Zapf Bandit

www.zapfbandit.com

Link to comment
Share on other sites

Most reports of 'broken SWI' are the result of not notifying the BIOS that the interrupt was handled and the SWI appears to hang. See here for details:

 

http://www.double.co.nz/nintendo_ds/nds_develop8.html

 

In a nutshell, with libnds, you need to set VBLANK_INTR_WAIT_FLAGS to indicate that you've handled the interrupt. If you don't do this, the wait for interrupt SWI will appear to hang as it is never notified that the interrupt occurred. So in your interrupt routine, when handling the vblank do:

 

VBLANK_INTR_WAIT_FLAGS |= IRQ_VBLANK;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...