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 > HBlank questions

#7858 - doragasu - Thu Jun 26, 2003 11:40 pm

Well, I have a few questions:

1. If you turn on HBlank interrupts, how many interrupts per frame are generated? 160? 228?

2. If you turn on repeated DMA and program it to start at HBlank, how many DMA transfers are done? 160? 228?

Thanks in advance

#7870 - tepples - Fri Jun 27, 2003 7:25 am

The CowBite spec states that hblank DMA does not trigger during vblank, but hblank interrupts do. Results of my tests on GBA hardware corroborate this.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7884 - Drago - Fri Jun 27, 2003 11:54 am

Yes, HBlank irq triggers on vblank, so you get 228 calls per frame. But HBlank DMA is a bit tricky, because it does not performs transfers on vblank, but vblank does not stop the transfer.
What this mean is: lets say you have a table storing 160 values and you want to transfer one value of the table on each hblank. When line 160 is reached the transfer is suspended for the whole vblank period and is resumed on line 0, but reading from the position 161 of the table. So you need to stop the dma transfer and reset the registers on the vblank period in order to repeat the transfer on next frame.
This is the hardware behaviour, Visualboy behaves different. Visualboy do stop the transfer, so no reloading is needed on vblank.

#7896 - tepples - Fri Jun 27, 2003 7:12 pm

Drago wrote:
This is the hardware behaviour, Visualboy behaves different. Visualboy do stop the transfer, so no reloading is needed on vblank.

Actually, VisualBoyAdvance 1.4 and 1.5 seem to do it correctly according to my test code that sets up a DMA of 320 lines of palette changes and starts it every other frame. What version of VBA are you running?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7902 - Drago - Sat Jun 28, 2003 12:07 am

My reference for the Visualboy behaviour is this post I sent some months ago:

http://forum.gbadev.org/viewtopic.php?t=672

My info can perfectly be out of date as many versions of VBoy have been released since then. Thanks for your point, tepples, I should update my VBoy...;)

#7936 - doragasu - Sat Jun 28, 2003 10:59 pm

So with DMA, you get 160 transfers per frame and need to reset the transfer, and with HBlank interrupts you get 228 interrupts per frame, right?

Another question...
when you get the first HBLANK interrupt (REG_VCOUNT = 0) the first line of the screen is or isn't drawed?

#7949 - tepples - Sun Jun 29, 2003 6:19 am

doragasu wrote:
So with DMA, you get 160 transfers per frame and need to reset the transfer, and with HBlank interrupts you get 228 interrupts per frame, right?

Correct.

Quote:
when you get the first HBLANK interrupt (REG_VCOUNT = 0) the first line of the screen is or isn't drawed?

I haven't experimented with precise timing of hblank interrupts or vcount interrupts, but I do know that hblank DMA occurs at the end of drawing a scanline, so copy the first scanline's values (e.g. bgaffine[0]) to registers during vblank and then start the DMA from bgaffine[1].
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#7970 - DekuTree64 - Sun Jun 29, 2003 6:06 pm

I'm pretty sure HBL interrupts occur at the end of the scanline, and have a little while before the next line starts to draw, and VCOUNT interrupts occur right at the start of the scanline, when REG_VCOUNT increments. I haven't experimented very thoroughly, but in my RPG's battle system, I change the screen data for the status window on VCOUNT, and the first 8 pixels of the line where it changes are garbled, so I think it's starting to draw while the interrupt is executing, and then getting scrambled when it changes things (since it updates 8 pixels at a time). For that reason, I think it would be better to have a VCOUNT interrupt the line before, which sets an HBL IRQ or DMA to start on HBlank to do the work.

#8154 - doragasu - Thu Jul 03, 2003 8:16 am

Thanks, now it's time to code some nice scanline effects!!!