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.

ASM > Reading DMA status registers

#178216 - Bregalad - Wed Aug 27, 2014 10:41 pm

Hello,

I have a problem. I want to try to know if HBlank DMA is active by reading the DMA status register (in this case, DMA3CNT or 0x40000DE) and see bit 15, and I initiate a memory transfer only if this is not the case. However this doesn't seem to work.

Actually it seems that just the read instruction screws things up, even if I only read and write nothing. This is really strange. The documentation says we can read the status register, but it does not mention what the read returns, nor if there is any side-effect.

VBA emulates it correctly (i.e. the weird behaviour is the same as real hardware) so at least this behaviour is known.

I tried both 16-bit and 32-bit reads, without success (16-bit reads sounds a better idea to avoid reading the illegal 0x40000DC).

#178219 - Bregalad - Fri Aug 29, 2014 5:52 pm

I have another question in regard to DMA :

What happens if a Vblank (or any other) IRQ fires during a DMA transfer ? Will the CPU :
1) continue to be halted until the DMA is finished, then serve the IRQ

2) Serve the IRQ right away, and continue the DMA once the CPU returns in USER mode

#178221 - DekuTree64 - Sat Aug 30, 2014 7:55 am

DMA always takes precedence over CPU, so interrupts will not be serviced until the DMA finishes.

And by checking that HBlank DMA is active, I assume you just mean enabled, and not currently transferring? Because if it is currently transferring, then the CPU is paused so you'd never see it :-s

I thought it was ok to read DMA3CNT and check bit 15, but maybe not. I suppose you could just make a global variable to keep track of whether you have an HBlank DMA set up. But now I am kind of curious whether reading DMA control registers has side effects...
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#178222 - Bregalad - Sat Aug 30, 2014 4:38 pm

Oh thank you, this is very helpful.

Reading DMA definitely has a side effect, it might restart the transfer(s) if one is currently pending or something like that. All I can say is that apparently the side effect, although undocumented, is somehow correctly emulated on Visual Boy Advance.