Why not to DMA this?

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
HCKTROX
Interested
Posts: 27
Joined: Wed Mar 24, 2010 1:15 am
Location: Chile

Why not to DMA this?

Post by HCKTROX » Sat Dec 26, 2015 8:42 pm

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?
skype: hcktrox

Mask of Destiny
Very interested
Posts: 616
Joined: Thu Nov 30, 2006 6:30 am

Re: Why not to DMA this?

Post by Mask of Destiny » Sat Dec 26, 2015 10:00 pm

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).

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Why not to DMA this?

Post by Sik » Sun Dec 27, 2015 1:05 am

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
Sik is pronounced as "seek", not as "sick".

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Re: Why not to DMA this?

Post by TmEE co.(TM) » Sun Dec 27, 2015 10:21 am

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).
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Why not to DMA this?

Post by Sik » Thu Dec 31, 2015 9:03 pm

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.
Sik is pronounced as "seek", not as "sick".

Post Reply