gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > DMA vblank behaviour?

#167583 - brave_orakio - Thu Mar 19, 2009 3:46 am

Hi guys, I have another question.


I am currently using a DMA vblank to update the OAM, so no problem there, it works perfectly. The problem begins when I put another DMA vblank before or after the copy to OAM. I am using the second vblank DMA copy to update the background so it would scroll smoothly. However, this method messes up the vblank copy. Whichever is called first has priority so one of the updates become choppy, depending on which is called second. Isn't DMA supposed to wait for vblank if it isn't vblank yet or does it skip the copy entirely?
_________________
help me

#167591 - Dwedit - Thu Mar 19, 2009 12:41 pm

Try eliminating your "DMA transfers timed to start at Vblank".
Instead, use a vblank IRQ handler, and do immediate DMA copies there. Transfer OAM first, then background. You'll most likely have tons of Vblank time remaining for more tearing-free transfers.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#167613 - brave_orakio - Fri Mar 20, 2009 2:04 am

I see. I have tried using an interrupt before so it should be no problem to implement it.

However that does raise another question. When I used an IRQ to update OAM from my previous experiments, it seems that for example I move my sprite by 1 pixel. But then, its not yet Vblank time so it moves again by another pixel. Now when Vblank comes, the IRQ triggers and the OAM updates. The sprite moves more than 1 pixel because of this. kinda like jumping 2 pixels or more.

Would you suggest putting a wait for vblank to finish loop inside the IRQ to sync with the screen?
_________________
help me

#167614 - Dwedit - Fri Mar 20, 2009 2:41 am

You are using an OAM buffer, right?

Usually you'd want this to happen:
game logic runs for a frame's worth of code
game updates OAM buffer (if necessary, make this part uninterruptible, or use page flipping on two OAM buffers)
Wait for vblank
---
vblank happens
copy OAM buffer
copy other video stuff
return from IRQ
---
Game logic runs...

I have no idea how this could fail.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#167615 - brave_orakio - Fri Mar 20, 2009 3:12 am

Gah! I see my error. I'm doing wait for vblank to finish after copying buffer to OAM memory instead of wait for vblank to arrive before copying to OAM memory! I thought I might be able to save a lot of cycles like this.

Yes I do use an OAM buffer. I should probably do the wait for vblank loop right after my OAM buffer sorts yes?
_________________
help me