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.

Coding > HDMA and HBlank writing to same area (note and question)

#34389 - DiscoStew - Tue Jan 18, 2005 10:02 pm

I've been working in the area of the HBlank, and for all my background stuff (which I plan to put together into a library), I use HDMA, so I wouldn't need to worry about it every HBlank. However, in another part of my code, which is separate from my BG stuff, I want to overwrite a background section that the HDMA writes to.

On both VBA and No$GBA, both allow the section to be rewritten after the HDMA before stuff is displayed on the scanline, and displays the BG correctly (which is what I wanted). But on hardware, the BG is messed up as if it is mixing the 2 things together, like my manual code starts going, then in the middle of it the HDMA inits, then the rest of my manual code writes the rest. That was just a note to everyone trying to mix the 2, if you try doing this. Now the question...

Because of this, I've got to choose which route I want to go in fixing this, since both my BG and other code will be in separate libraries in the future. Should I...
  1. Make functions in both libraries that extracts some data from one library, and inserts it into another library, so that it can rewrite memory that HDMA read from.
  2. Remove HDMA altogether from my BG library, and replace it with my own routine that is executed every HBlank, so that there won't be any mixing do to interrupts.
Of course, if anyone has a suggestion, I'd sure like to know what that is. I'm just trying to find a good, stable method that is fast also.

thx in advance
_________________
DS - It's all about DiscoStew

#34390 - poslundc - Tue Jan 18, 2005 10:12 pm

I didn't follow 100% of everything you said there, but it's been my experience that one generally shouldn't mix HDMA and HBlank interrupts. Either do one or the other... there's little practical reason for doing both.

Dan.

#34392 - tepples - Tue Jan 18, 2005 11:16 pm

If you want to modify a hardware register using hblank DMA, but you want to use hblank interrupts to modify it differently for a given set of scanlines, then write that different modification to the HDMA buffer instead of directly to the registers.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#34397 - DiscoStew - Wed Jan 19, 2005 12:12 am

poslundc wrote:
but it's been my experience that one generally shouldn't mix HDMA and HBlank interrupts. Either do one or the other... there's little practical reason for doing both.

I very much agree with you, as the results can be very odd. It seemed to work right on emulators (since they don't mimic hardware exactly), but it's the hardware that the stuff needs to work on.
tepples wrote:
If you want to modify a hardware register using hblank DMA, but you want to use hblank interrupts to modify it differently for a given set of scanlines, then write that different modification to the HDMA buffer instead of directly to the registers.

That would seem like the logical choice, since I've already got my HDMA setup working very nicely, plus since it's using DMA, chances of slight artifacting and other things of the nature are minimal from my own tests. I guess I should go with that, which I tried explaining in my first choice. Since both pieces of code will be in different libraries, I will need to make an extract and insert function.

thx for your help guys.
_________________
DS - It's all about DiscoStew