Dma works perfect in gens k-mod but not in kega fusion

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Post Reply
sega16
Very interested
Posts: 251
Joined: Sat Jan 29, 2011 3:16 pm
Location: U.S.A.

Dma works perfect in gens k-mod but not in kega fusion

Post by sega16 » Sun May 15, 2011 6:43 pm

I made a little demo that displays 5 frames of some animated water.It should on the vblank load the tiles with dma and it works perfect when I use gens kmod but it takes more than one frame on kega fusion so it has flickering because it is using the new pallete but still showing the old tiles also it has has dma glitches.anyway here is the code:

Code: Select all

	asm
DPORT    EQU $C00000    ; VDP Data port
CPORT    EQU $C00004    ; VDP Command port
	end asm
	'disable	INTERRUPT VBLANK
	on	VBLANK gosub vint
	framecounter=12	'60frames per second divider by 5frames per second equals 12
	framecount=0
	movetoa0	LblPtr&(video0pal)
	ink 1
	bgcolor	1,0
	drawtilesinc	128,0,0,40,28
	enable	INTERRUPT VBLANK
	end
	
vint:
	'disable	INTERRUPT VBLANK
	framecounter--
	if framecounter = 0 then
	framecounter=12
	goto	redraw_frame
	else
	goto	no_frame_redraw
	endif
redraw_frame: 
	if framecount = 4 then
	movetoa0	LblPtr&(video0pal)
	framecount=0
	goto	doframe
	endif
	framecount++
doframe:
	asm
	move.w	#$80,d0;128
	move.w	#$460,d3;1120
	move.w	#$5,d5
	move.l	#$8c00,d6
	move.l	$FFFFFF08.w,d4
	move.w	d0,$FFFFFF00.w
	move.w	d3,$FFFFFF02.w
	move.w	d5,$FFFFFF04.w
next_frame:
	move.w	$FFFFFF00.w,d0
	move.w	$FFFFFF02.w,d3
	move.w	$FFFFFF04.w,d5
	movea.l	d4,a0
LoadPalette:            ; Setup 1 palette  D0=Pal index, A0=Source address
 LSL    #5, D5
 SWAP   D5
 OR.L   #$C0000000, D5
 MOVE.L D5, (CPORT)
 MOVEQ  #7, D5
NextPal:
 MOVE.L (A0)+, (DPORT)
 DBRA   D5, NextPal
	add.l #$20,d4
	movea.l	d4,a0
	
;LoadTiles:              ; D0=Start tile , D3=tiles , A0=Source address
; LSL.W  #5, D0
; AND.L  #$FFFF, D0
; LSL.W  #4, D3
; SUBQ   #1, D3
; MOVE.L #$40000000, D2  ; D2=VDP command
; MOVE.L D0, D1
; LSL.L  #2, D1
; CLR.W  D1
; SWAP   D1
; OR.L   D1, D2          ; Add Address bits 14 and 15
; AND.L  #$3FFF,D0
; SWAP   D0
; OR.L   D0, D2          ; Add rest of the Address bits
; MOVE.L D2, (CPORT)     ; Write command+screen pointer
; MOVE.L #DPORT, A1
;NextTileByte:
; MOVE.W (A0)+, (A1)
; DBRA   D3, NextTileByte
	
LoadTiles2:             ; D0=Start tile , D3=tiles , A0=Source address
 LSL.W  #5, D0          ; uses DMA
 MOVE.W D0, D1
 AND.W  #$3FFF, D0
 OR.W   #$4000, D0
 SWAP   D0
 ROL.W  #2, D1
 AND.W  #3, D1
 MOVE.W D1, D0
 MOVE.L D0, D2
 LSL.W  #4, D3
 MOVE.W D3, D0
 JSR    DoDMAtoVRAM
	add.l d6,d4
	move.l	d4,$FFFFFF08.w
	clr.l	d2
	clr.l	d1
	end asm
	'enable	INTERRUPT VBLANK
no_frame_redraw:
	return	'end of the vblank
	asm
DoDMAtoVRAM:            ; Does DMA to VRAM
 MOVE.L #CPORT, A1      ; D0 = WORDs to transfer                        
 MOVE.L #$94009300, D1  ; D2 = VRAM address
 OR.B   D0, D1          ; A0 = source address
 LSR.W  #8, D0
 SWAP   D0
 CLR.W  D0
 OR.L   D0, D1
 MOVE.L D1, (A1)
 MOVE.L A0, D0          
 LSR.L  #1, D0          
 MOVE.L #$97009500, D1
 OR.B   D0, D1
 LSR.W  #8, D0
 OR.W   #$9600, D0
 MOVE.W D0, (A1)        ; MID
 SWAP   D0
 SWAP   D1
 AND.B  #$3F, D0
 OR.B   D0, D1
 MOVE.L D1, (A1)        ; LOW, HIGH
 OR.B   #$80, D2
 MOVE.L D2, (A1)
	rts
	end asm
video0pal:
	datafile	water0.png.pal,bin
video0:
	datafile	water0.png.pat,bin
video1pal:
	datafile	water1.png.pal,bin
video1:
	datafile	water1.png.pat,bin
video2pal:
	datafile	water2.png.pal,bin
video2:
	datafile	water2.png.pat,bin
video3pal:
	datafile	water3.png.pal,bin
video3:
	datafile	water3.png.pat,bin
video4pal:
	datafile	water4.png.pal,bin
video4:
	datafile	water4.png.pat,bin

declare asm sub movetoa0(d0.l)
	move.l	d0,$FFFFFF08.w
end sub
Also the dma code is from tido's mega libary
also here is the rom source and all the tiles:
http://www.mediafire.com/?ouded4q3m4r3x9u
thanks for your help.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Mon May 16, 2011 8:00 am

Be careful with Gens as it doesn't emulate properly the VRAM access time on Ctrl port. Although it should be correct on DMA i'm more confident in Kega timing so you should expect the same problem to occurs on real hardware !

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

Post by TmEE co.(TM) » Mon May 16, 2011 3:06 pm

Kega Fusion has very accurate DMA emulation, so I'm with Stef here, you'll probably get that same error on real hardware 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

Oerg866
Very interested
Posts: 211
Joined: Sat Apr 19, 2008 10:58 am
Location: Frankfurt, Germany
Contact:

Post by Oerg866 » Mon May 16, 2011 3:14 pm

DMA is only useful if you know how to do it. Infact, anything is. Please lern to know what you are using before asking questions.

Post Reply