Page 1 of 1

Why not to DMA this?

Posted: Sat Dec 26, 2015 8:42 pm
by HCKTROX
In a while I'll try to do some effect based in Hblank. First of all I went on analyzing some other code, and this is the code that Sonic the Hedgehog uses for reloading the palette for the water:

Code: Select all

DrawWater:
		move	#$2700,sr
		tst.w	(f_hbla_pal).w	; is palette set to change?
		beq.s	@nochg		; if not, branch
		move.w	#0,(f_hbla_pal).w
		lea	($C00000).l,a1
		lea	(v_waterpal).w,a0 ; get palette from RAM
		move.l	#$C0000000,4(a1) ; set VDP to CRAM write
		move.l	(a0)+,(a1)	; move palette to CRAM
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.l	(a0)+,(a1)
		move.w	#$8A00+223,4(a1) ; reset HBlank register
@nochg:
Why doesn't it reload the CRAM with DMA? Does it have anything to do with the CRAM dots bug? (oh, and is there any available emulator that shows this behavior?). I really think it has a great purpose, from VBlank the engine just does reload the CRAM with DMA...
What should I take care of, while working with CRAM on HBlank?

Re: Why not to DMA this?

Posted: Sat Dec 26, 2015 10:00 pm
by Mask of Destiny
Probably to reduce interference with sample playback. DMA locks the Z80 out of the bus until it's complete whereas the Z80 will get a chance to acquire the bus after each write with a software copy. It will still be kind of messy as those writes can block for a while due to the limited external slots. Probably better to disable the display during HBlank and do DMA, but perhaps that trick was not known at the time (I think Mickey Mania is the only commercial title to do so).

Re: Why not to DMA this?

Posted: Sun Dec 27, 2015 1:05 am
by Sik
1) This is in active scan, so DMA can't outpace 68000
2) Given the above, setting up the DMA would be slower

In other words: using DMA would be a bad idea in this case

Re: Why not to DMA this?

Posted: Sun Dec 27, 2015 10:21 am
by TmEE co.(TM)
It would even be beneficial to stick some NOPs between the instructions so that 68K would get stalled less often (and thus Z80 playback will improve too).

Re: Why not to DMA this?

Posted: Thu Dec 31, 2015 9:03 pm
by Sik
Take it further: slow it down enough to not stall but not so much that the FIFO gets fully flushed. So you still get the maximum transfer speed without the bus being hogged for the Z80.