Dma works perfect in gens k-mod but not in kega fusion
Posted: 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:
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.
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 here is the rom source and all the tiles:
http://www.mediafire.com/?ouded4q3m4r3x9u
thanks for your help.