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 H-Blanks.

#1121 - dooby6 - Tue Jan 14, 2003 8:32 pm

Hello everybody,

I was just wondering what the difference was between HDMA and a H-Blank interrupt.

Dooby6.

#1122 - Splam - Tue Jan 14, 2003 8:49 pm

HBlank interupt is an interupt :) whereby you must service the interrupt and can run your own code from it. It's triggered (if requested to) during the horizontal blanking period. As I say, you can write code just like you normaly would to do whatever you want.

HDMA is a dma and can only copy data from one place to another, there are no instructions involved once it is running (ie you can't get it to call your own code). You can use hdma for something like copying a new palete on each line of the screen or something like changing the x position of a sprite or the screen (to make it wobble or other effects).

#1131 - dooby6 - Tue Jan 14, 2003 9:48 pm

Okay I know how to get a HBlank interrupt working but could you tell me how how to set up a HDMA.

Thanks alot,
Dooby6

#1133 - Splam - Tue Jan 14, 2003 10:05 pm

I'll give it a shot ;)

Presuming here usage of dma3...

You need to set the source, destination and control registers..

Source and destination, easy, you know what you want to copy and where you want it to go :)

Control register..

You need to set the bits in the control register for DMA_ENABLE, DMA_HBLANK for starters, that will ensure the dma is started and is in HDMA mode.

From there on its pretty much your own choice of what you do, the rest of the bits in that register are for things like source/destination reload or increment etc + should the dma repeat or not and finally the number of transfers to do.

It's pretty hard to tell you exactly how to set it up because I don't know what you want to do with it but here's an example I found in some code of mine before I did it in asm instead..

Code:

   //DMA3 Source Addresss
   REG_DM3SAD = 0x2000016;

   //DMA3 Destination Address
   REG_DM3DAD = 0x5000000;

   REG_DM3CNT = DMA_ENABLE | DMA_HBLANK | DMA_32 | DMA_SOURCE_INCREMENT |DMA_DEST_RELOAD |DMA_REPEAT|2;


What that does is set the hblank dma to read data from ram at address 0x2000016 and store it to the palette registers 0x5000000, it copies 2 32bit values on each line. The source address is a table of 4 colour registers for each line of the screen.

Those DMA_ things mean the following...

DMA_ENABLE triggers the dma to start
DMA_HBLANK tells it to go into hblank mode
DMA_32 means copy 32bit values
DMA_SOURCE_INCREMENT Keep incrementing the source address on each occurance of the hdma
DMA_DEST_RELOAD set the destination back to its initial value on each hdma (because I want to copy the the same palette entries)
DMA_REPEAT makes sure the dma happens on every line (without this it would copy 1 lot of data then stop)
2 is the number of transfers to do 2*32bit

You need to call this code on the vblank because if you don't it will just keep going forever incrementing the source address (because of the DMA_REPEAT).

You may have totally different definitions for the "bit codes" than I do but they should make sense.

Hope that helps.

#1205 - dooby6 - Wed Jan 15, 2003 6:31 pm

Hi,

Thanks that helped alot, but everytime I try it, it just causes the screen to black out. I tried in a forever loop and have done it outside the loop but the same effect just keeps happening. I' m doing in asm on the Goldroad assembler, and just trying to make the screen wobble effect, and yes I am a newbie on GBA Dev=).

Thanks,
Dooby6

#1211 - zeuhl - Wed Jan 15, 2003 6:54 pm

I thought accessing the palette registers required 16-bit access, thus using the 16-bit DMA transfer mode.

if 32 bit access works (ie converting a single 32-bit access to two 16-bit accesses when writing to the palette registers), it obviously should be faster when reading IWRAM.

the GBA hardware just rocks ;-)

#1219 - Splam - Wed Jan 15, 2003 7:29 pm

@zeuhl
Yeah, seems to be a popular misconception that you can only do 16bit writes, you can do 16 or 32, just not 8 ;) the 16bit mode is in case you only want to write say an odd number of palette registers (other reasons too).

@dooby6
Not sure what your problem could be, lots of things will blank the screen, it's possible you're writing to the wrong register, writing too much etc etc.

#1240 - pulstar_3 - Wed Jan 15, 2003 10:18 pm

Hi,

I got a problem with HDMA. I try to create the wobble effect on a text bg in mode 0. I have a sine wave that takes the values for the wobble, and put the HDMA ion a v-blank interrupt but it just doesn't work at all. Any comments.

Cheers