DMA failure on different consoles.

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

Post Reply
Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

DMA failure on different consoles.

Post by Jpg3D » Mon Oct 31, 2016 8:12 pm

Hi, after months without being able to work on my project, I'm programming my rom again. I'll try to explain the best i can the problem i have.
I hope any of you can help me to fix this error.

The pistol's tiles are DMAed to VRAM. The text tiles are filled to the VRAM by writting them using data port using a MOVE loop.

I tried to transfer the pistol's tiles using DMA and tested the rom on the consoles that i got access.

This is a pic testing the rom on my own console. It works fine and i dont get any glitches. Tested on MegaEverdrive.
Image

This is what i get on my friend's console. Tested on Everdrive.
Image


This is the fragment of my code that i use to fill the VRAM using DMA

Code: Select all


DMATOVRAM				equ $40000080
******** Entrada: D0 number of bytes/words
********               D1 = 3 bytes DMA source
********               D2 = 2 bytes DMA destination

DMAGEN:
        MOVE.W #$8F02,$00C00004   * increment 2 bytes 
        MOVE.W #$8174,$00C00004   activate dma
        
        MOVE.W #$9300,D4  * Low Counter
        OR.B   D0,D4
        MOVE.W D4,$00C00004  
        ASR.W  #8,D0
        MOVE.W #$9400,D4  * High Counter
        OR.B   D0,D4
        MOVE.W D4,$00C00004  

        LSR.L  #1,D1
        MOVE.W #$9500,D4  * Low source adress
        OR.B   D1,D4
        LSR.L  #8,D1
        MOVE.W D4,$00C00004  

        MOVE.W #$9600,D4  * MID source adress
        OR.B   D1,D4
        LSR.L  #8,D1
        MOVE.W D4,$00C00004  

        MOVE.W #$9700,D4  * High source adress
        AND.B  #%01111111,D1
        OR.B   D1,D4
        MOVE.W D4,$00C00004          
        
        ASL.L  #2,D2           * Destination address and operation
        LSR.W  #2,D2
        SWAP   D2
        OR.L   #DMATOVRAM,D2
        MOVE.L D2,$00C00004  
        
        RTS
I dont have any idea why on different consoles the same code results on a different behaviour.
What can be causing this DMA failure?

Really thank you for your help.

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

Re: DMA failure on different consoles.

Post by Mask of Destiny » Mon Oct 31, 2016 10:08 pm

What model and revision do you and your friend have?

Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

Re: DMA failure on different consoles.

Post by Jpg3D » Mon Oct 31, 2016 10:34 pm

Mine is :Megadrive 1 PAL-B(VE) 1601-07 <-- Works fine

Friend's :Megadrive 1 PAL-G 1601-18 <-- Glitchy DMA

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

Re: DMA failure on different consoles.

Post by Stef » Tue Nov 01, 2016 11:14 am

It looks like a memory timing issue... Sometime small voltage difference can make the everdrive memory behaves differently. For instance the everdrive flash speed cannot be the same depending on which MD system i'm using it, i have to test on my "slowest" MD to ensure it works everywhere.
Still for me it only happened during flashing and never during in game memory access condition.
Also you used MegaEverdrive on your system while using simple Everdrive on your friend system. MegaEverdrive has some extra hardware allowing extended ROM area... maybe it also affects positively your code in some way.
Do you have a sample test rom so we can eventually test on our own system ? I've a PAL and JAP MD1 with an everdrive...

Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

Re: DMA failure on different consoles.

Post by Jpg3D » Tue Nov 01, 2016 12:33 pm

Here's the rom
https://ufile.io/56a7

I'm pretty sure that is my fault. Probably i'm missing something on my DMA function that causes this failure on different cartidges, because other homebrew works fine on myfriends MegaDrive.

Also i tested it on another system.
MegaDrive 2 -> MK-1631-50 <-- Works Perfect with my MegaEverdrive

Natsumi
Very interested
Posts: 82
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: DMA failure on different consoles.

Post by Natsumi » Tue Nov 01, 2016 2:46 pm

Sanity check; disable ints. Always disable ints when writing to VDP unless you can be sure there is no possibility of ints happening (like during VInt with no HInts). Or better yet, write better DMA code. This one here is terribly slow, and increases likelihood of ints happening during it. The best case is just using raw values with move.l's and one move.w, to (aN). This is generally what actual games do too.

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

Re: DMA failure on different consoles.

Post by Sik » Tue Nov 01, 2016 6:55 pm

Actually the best case is to store the commands in a queue and then send the entire queue to the VDP when vblank starts (not talking about the vblank interrupt, just the main loop), this gives you the most optimal bandwidth usage and ensures DMAs won't clash with interrupts unless you make too many of them. It also means you can safely spend more time building the DMA command since the only critical part is when the queue is being sent to the VDP.

On the flipside, it also means you need to keep any data to be transferred around until the next frame. So don't use this for data put in local variables since they stop existing once you return from the function.
Sik is pronounced as "seek", not as "sick".

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

Re: DMA failure on different consoles.

Post by Stef » Tue Nov 01, 2016 8:46 pm

The rom size is 21 KB, i strongly suggest you to align its size to 128 KB boundary... That may explain the difference you observe between the MegaEverdrive and the Everedrive.

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

Re: DMA failure on different consoles.

Post by TmEE co.(TM) » Wed Nov 02, 2016 4:31 pm

ED requires 128KB alignment to work properly, or at least used to require the alignment.
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

HardWareMan
Very interested
Posts: 745
Joined: Sat Dec 15, 2007 7:49 am
Location: Kazakhstan, Pavlodar

Re: DMA failure on different consoles.

Post by HardWareMan » Wed Nov 02, 2016 6:48 pm

Tested with my system. Pistol appears correctly but very short time. About 0.5 sec. Everything else like on emulator. MD1 and my own flash cart.

Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

Re: DMA failure on different consoles.

Post by Jpg3D » Wed Nov 02, 2016 6:51 pm

I aligned the size to exactly 131.072 bytes (128kbs), blocked interrupts, and rewritted the DMA function so now it's much faster. It's almost a copy from the DMA function that you can find at this website.
http://www.hacking-cult.org/?r/18/25

Unfortunately the problem persists. 100% the same behaviour as i menctioned before. Perfect functionality on my megadrive and exactly the same glitchy stuff on my friend's one. The code runs right as expected when i remove the calls to DMA functions so im absolutely sure the problem is that im doing something wrong when implementing the DMA function.

Code: Select all


DMA2VM MACRO

		MOVE.W	#$9400+(((LENGTH)>>9)&$FF),($C00004).l    
		MOVE.W	#$9300+(((LENGTH)>>1)&$FF),($C00004).l
		
		MOVE.W	#$9600+(((SOURCE>>1)&$FF00)>>8),($C00004).l   
		MOVE.W	#$9500+((SOURCE>>1)&$FF),($C00004).l
		MOVE.W	#$9700+((((SOURCE>>1)&$FF0000)>>16)&$7F),($C00004).l

        MOVE.L	#($80+((DESTINATION&$3FFF)<<16)+((DESTINATION&$4000)>>14)+((%001&$4)<<2)+((%001&$3)<<30)),($C00004).l    
    
       ENDM

At this point i dont have any idea what can be causing this bug.

Natsumi
Very interested
Posts: 82
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: DMA failure on different consoles.

Post by Natsumi » Fri Nov 04, 2016 2:01 am

Now, this may be completely crazy suggestion, but try clearing the RAM after init but before any other DMA. Don't bother making it efficient, you just want to waste time. This fixed major issues with a homebrew I wrote earlier. Without this, the graphics wouldn't look right, or just nothing loaded. Adding it and I never had issues since.

Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

Re: DMA failure on different consoles.

Post by Jpg3D » Fri Nov 11, 2016 6:26 pm

Thank you all for you help. It really helped me to think back to my first code and fix it.

Finally the error was fixed after rewritten A LOT of ugly n00bish code. Probably there were something wrong at my very beginning lines because i had not really good idea of how to program this machine. I fixed many bugs so i dont know really well where my code was fixed. After a lot of tests it's working 100% as i want.

<3

Post Reply