Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Img2CPC add option for 2D array output #52

Open
Arnaud6128 opened this issue Jul 25, 2017 · 2 comments
Open

Img2CPC add option for 2D array output #52

Arnaud6128 opened this issue Jul 25, 2017 · 2 comments
Assignees
Milestone

Comments

@Arnaud6128
Copy link
Collaborator

Arnaud6128 commented Jul 25, 2017

The objective is drawing easily a part of a large sprite.

If i take example of bitmap letters, i have to generate tileset in order to select directly the letter i want to draw.

u8* const letter_tileset[27] = { 
	letter_00, letter_01, ...
};

const u8 letter_00[8 * 8] = { ... }
const u8 letter_01[8 * 8] = { ... }

But the Tilesets uses 27 * 2 bytes.

I was thinking about generating 2d sprite array.

const u8 letters[27][8*8] = { {.....}, {....}, ... };

In this way we can directly access the sprite part we need and it doesn't take more memory to realize this.

@Arnaud6128 Arnaud6128 changed the title Img2CPC adding option for 2D array output Img2CPC add option for 2D array output Jul 25, 2017
@AugustoRuiz
Copy link
Collaborator

AugustoRuiz commented Jul 25, 2017 via email

@lronaldo
Copy link
Owner

@Arnaud6128 Actually, if you do not ask for tileset generation, you will get exactly what you want, except for the C declaration of the array. All the data about the tiles/sprites will be in the same order in memory, be it in individual arrays or in a 2D array. You can add a new symbol to your code and use your array as a 2D array this way:

/// Create a label at the start of the 2D array. 
/// We need a dummy function to insert assembly code (otherwise SDCC complaints)
/// We declare the function __naked to prevent it from generating any additional code
void dummyf() __naked {
__asm
      _letters2D::
__endasm;
}
const u8 letter_00[8 * 8] = { ... } 
const u8 letter_01[8 * 8] = { ... } 

Then you can use your 2D array letters2D just by declaring it in the header file or wherever you need it:

extern const u8 letters2D[27][8*8];

Then the compiler will asume a 2D array that starts at the place or your label.

However, remember that you are trading memory space for computational time. When accessing members of your 2D array, calculations will be performed (base_location_of_the_array + size_of_dimension2 * X + Y). This will be calculated either by the compiler (when you write down letters2D[X][Y] or by yourself and your routines when you needed it.

Also remember that you can directly refer to the generated symbols (level_XX) and save the calculation time, but loose access generality (not possible to make loops and other things to refer to all letters).

Depending on your needs, you may prefer one approach or the other.

Meanwhile, I assume that @AugustoRuiz will be able to easily add the option to Img2CPC.

@lronaldo lronaldo added this to the delayed milestone Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants