Re: Taking a part from character

```On Mon, Jan 03, 2000 at 12:04:15AM +0000, Wille Huuskonen wrote:
> I have a character here: (this is just a example)
>     unsigned char cars[9*6]={
>     0, 3, 3, 0, 0, 0, 3, 3, 0,
>     9, 9, *9, *9, 9, 9, 8, 8, 0,
>     6, 4, *4, *4, 4, 6, 7, 7, 8,
>     2, 4, *4, *4, 4, 2, 7, 7, 8,
>     1, 1, 1, 1, 1, 1, 5, 5, 0,
>     0, 3, 3, 0, 0, 0, 3, 3, 0};
>
> And I want to get those bytes(?) marked with * to a
> char[2*3] car.

Looks like you're gonna have to copy it manually, e.g.:

unsigned char car[2*3];
int x,y;
for(y=0;y<=2;y++) {
for(x=0,x<=1,x++) {
car[y * 2 + x] = cars[(y+1)*9+(x+2)];
}
}

This is how you write a basic blitter routine in C also. That's why they're so darned slow. ASM routines do the same thing, essentially, but are optimized for the particular CPU. Of course around here we take advantage of gfx card accel whenever possible. :)

Anyway, barring special cases like optimizing for SIMD, the only way to copy a whole array or part of one is to copy it piecewise, element by element. If you have a contiguous rectangular array mapped as a single-dimensional array, then the function for determining the element at (x,y) is:

array[y*MAXX+x]

where MAXX is the X-dimension of the whole array; the number of columns in a row.

```