dmaCopy of 8bit bmp, problem...

Post Reply
Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

dmaCopy of 8bit bmp, problem...

Post by Sylus101 » Sun Feb 08, 2009 7:11 pm

I'm using a dmaCopy method of scrolling a large bitmap image. Basically, the 256x256 background stays stationary and I'm moving around in the bg array and dma'ing to the screen is scrolling happens. The problem is (I don't have this issue with a 16bit bg) that it's choppy in the x direction. The best way I can describe it is that every other change in x shifts the entire layer off by one and then back again. Here's the code:

Code: Select all

//COL_BG is defined in as:
//#define COL_BG ((u16*)0x6020000)
//VRAM Bank B... both A and B are mapped to Main Engine Background

for(i = 0; i < 192; i++){
	dmaCopyWords(3, &colmap_bin[bg->x + ((i + bg->y)*(bg->width))], &COL_BG[(i << 7)], 256);
}
I've used very similar code (nearly identical) on a 16 bit background and it scrolls smoothly. All this is doing is writing each horizontal line to memory, adjusting the starting position in the array by some x and y value. The Y direction scrolls smoothly. I'm really thinking I've got some kind a memory alignment problem, but I can't place it. If I pick up the right spot in the 8bit array, it should still copy an even chunk of the array into memory. I've been glaring at this for hours... help!
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

gmiller1018
Posts: 11
Joined: Mon Nov 12, 2007 10:47 pm
Location: Winter Springs Florida, USA

Re: dmaCopy of 8bit bmp, problem...

Post by gmiller1018 » Sun Feb 08, 2009 11:42 pm

you are doing a DMA of 32 bit pieces (WORD) so the address (source and destination have to be on 4 byte boundies (low order nibble must be zero). Your data might not be aligned correctly.
Gary Miller
CD Machine Architecture II, Operating System Concepts
Full Sail

http://www.fullsail.com

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: dmaCopy of 8bit bmp, problem...

Post by Sylus101 » Sun Feb 08, 2009 11:53 pm

With your other answer, I figured you might have posted here too. The moment I read what you wrong, it makes perfect sense now, but crud... I'm in trouble.

Do other copy methods like memcpy or swiCopy have the same restriction of alignment as DMA? After running several other tests what you've said is exactly what's happening. What I was seeing really, was it only moving every 4th change in x, which makes sense now. Switching to halfwords made it every 2nd, so there you go.

I really really really don't want to use a for loop... I have a bad feeling that that will be too slow. Any ideas?
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

gmiller1018
Posts: 11
Joined: Mon Nov 12, 2007 10:47 pm
Location: Winter Springs Florida, USA

Re: dmaCopy of 8bit bmp, problem...

Post by gmiller1018 » Mon Feb 09, 2009 12:04 am

Well .. you can move the data that is not aligned with the loop (either before or after the big piece) and then DMA from the aligned address to the appropriate aligned address. THat way the data you move in a loop is VERY small and you use DMA for the majority of the data. Just remenber that BOTH from and TO addressed have to be aligned for DMA.
Gary Miller
CD Machine Architecture II, Operating System Concepts
Full Sail

http://www.fullsail.com

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: dmaCopy of 8bit bmp, problem...

Post by Sylus101 » Mon Feb 09, 2009 12:17 am

I'm not too sure I follow... but I think I do. Exactly what I have is a large 8 bit image in .bin format so every pixel is one byte. Lets say for sake of argument that I know it is aligned using __attribute__ ((aligned (4))).

Using dmaCopyWords at &mybg[0] works fine, but does not again till at &mybg[4]. Every index in between just copies the same as if it were at &mybg[0].

In this case wouldn't I have quite a bit of unaligned data? Heck I don't even know (beyond a loop) how to approach in the case that I need &mybg[1], &mybg[2], or &mybg[3].

Now I'd go down to HalfWords so that it's only every other that is unaligned, but I'm sure I'm missing something in what you're suggesting (going to get a haircut, so if you answer I'll be back in an hour or so...).

EDIT - Well... so far it looks like swiFastCopy is going to be the fix... but Gary if you come back and can give any more insight I'd still appreciate it.
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest