CPCWiki forum

General Category => Programming => Topic started by: ronaldo on 21:36, 06 March 16

Title: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: ronaldo on 21:36, 06 March 16
After latest conversation about the game @EgoTrip (http://www.cpcwiki.eu/forum/index.php?action=profile;u=337) is developing, i started coding a new type of bitarray for CPCtelera (http://lronaldo.github.io/cpctelera): an array of 6-bits values. This new kind of bitarray is already included in latest master branch of CPCtelera in Github (https://github.com/lronaldo/cpctelera).

At the moment, there is no example on how to use 6-bits arrays. I will prepare one example soon and add it for next release.

However, as many people found difficult to understand the already existing bitarrays example (https://github.com/lronaldo/cpctelera/blob/master/examples/medium/bitArrays/src/main.c), I've also decided to create more explicit use-case examples. Here you are the first one, which shows how to use 1-bit bitarrays to draw and edit a tilemap (https://github.com/lronaldo/cpctelera/tree/master/examples/medium/bitArrayMaps1/src). The example is structured and commented for clarity. The interesting part is in the map.c file, which shows how to manually define a 1-bit tilemap (https://github.com/lronaldo/cpctelera/blob/master/examples/medium/bitArrayMaps1/src/map.c) and the functions to read and write its individual 1-bit values.

Could you please tell me if you find this example useful? I need your opinion to elaborate better examples.

Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: EgoTrip on 21:59, 06 March 16
I know this is off-topic but can you do the following for CPCtelera:

XOR sprites, sprite flipping (horizontally, vertically), sprite rotating (in 90 degree angles) and have the functions so you can use different combinations of flipping and rotating. It will save loads of memory on graphics instead of having 4x4x16 bytes for say the corners / walls of a room you could have just one and rotate it. That alone would be a saving of 384 bytes.

And a grab sprite routine would be great too, so you can grab a section of the screen and use as a sprite.

There was something else I wanted but can't remember it off the top of my head. I remember now: inverting sprite inks, so ink 0 becomes 3, ink 2 becomes 1 for mode 1, 0 becomes 15, 2 becomes 14 etc for mode 0.
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: ronaldo on 22:24, 06 March 16
@EgoTrip (http://www.cpcwiki.eu/forum/index.php?action=profile;u=337), almost all you have listed is already in the tasklist. On finishing with bitarrays, next thing will probably be sprite mirroring, mixing and clipping. Grabbing sprites has currently low priority, and ink changing is not added yet, but i take note. Thank you.

However, i'm paying much attention to documentation and examples. I think most of the features are unused or missused due to bad examples or lack of documentation. If you can give me feedback on the new example and others, it will be much appreciated.

Also, if any of you wanted to contribute examples, explanations or documentation, it would be awesome :) .

PD: You can always go to github's issues list (https://github.com/lronaldo/cpctelera/issues) and directly add your suggestions, questions or proposals.
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: ronaldo on 11:47, 08 March 16
Sorry for insisting, but I'd need some feedback on this:

Code example on using 1-bit bitarrays to create tilemaps (https://github.com/lronaldo/cpctelera/blob/master/examples/medium/bitArrayMaps1/src/map.c) (Full minieditor code (https://github.com/lronaldo/cpctelera/tree/master/examples/medium/bitArrayMaps1/src))

Could anyone give me feedback on this code example?
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: EgoTrip on 12:54, 08 March 16
I've not tried it yet, but from reading the example it does appear well laid out and well commented and easy to understand.

The thing about this type of bitarray though is that there are only on/off walls. You can't use this to show different tile graphics. The advantage is that if thats all you want it will save a lot of memory.
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: Arnaud on 13:15, 08 March 16
I'll take a look tonight.
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: SRS on 21:14, 08 March 16
Hi,

the example is well documented.

Also I do not understand why the binaries have to end with "C1" and so on - looks "hexa" to me ?

Other questions:

Greetings,

SRS
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: SRS on 21:39, 08 March 16
And the answers are:

C0,C1 and so on are the name of macro parameters. There are 10 parameters for the macro MAPROW, that correspond to the 10 binary numbers that compose 1 ROW (10 bytes = 80 bits). So, when you see something like this:
0b##C1  This stands for "concatenate 0b + C1" being C1 a number that is passed as argument to the macro. Therefore, when you write something like this:
MAPROW(11000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000011),  The compiler sees the expansion of that macro, that is:

0b11000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000011,  The concatenation of 0b + number, 10 times (C0 - C9 parameters).


   Updating CPCtelera full install each time is easy if you are using git. You only have to perform these two commands from inside CPCtelera root folder:
git pull
   ./setup --clean-reinstall   ## You could also use ./setup -cri
   With this you update your repository to with latest changes and then you compile tools and library again to ensure they are up-to-date.


   In case you are not using GIT, you can download a new version, unzip it into any folder you like (but assuming that folder will be the install place) and launch ./setup.sh. Once completed, you have new CPCtelera installed. If you had an old version in a different folder, you could then delete it, as new CPCtelera will be used, because setup process configures the recently installed one as CPCtelera root folder.


   With respect to pointers, I'm using <u8*> which is not the same as <u8>. <u8*> stands for "Pointer to u8", which means it is a 16-bits value that points to a u8 type.
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: Arnaud on 19:03, 09 March 16
Hello, i have read carefuly the file map.c.
Your example is easy to understand and we can see the interest of the use of the cpct_setBit and cpct_getBit.

My only remark is about the map array definition :

const CPCT_1BITARRAY(map, MAP_WIDTH * MAP_HEIGHT) { ...


I used to defined array or memory allocation in BYTE unit and with this macro CPCT_1BITARRAY i was a little lost because the map array size was defined in BIT (it was late when i read the code  ;) ).

I'd understand better :
#define NB_BIT_IN_BYTE 8
const map[MAP_WIDTH * MAP_HEIGHT / NB_1BIT_PER_BYTE] { ...


That all.
Title: Re: [CPCtelera] New bitarrays example and arrays of 6-bits values
Post by: ronaldo on 00:43, 10 March 16
@Arnaud (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1424) , thank you very much for the review :). It's nice to know that the example is useful. I will elaborate some more for the use of other bitarrays.


CPCT_1BITARRAY macro is exactly doing pretty much the same calculation that you are doing by hand. It is just a macro, and gets expanded to a u8 array definition. So, if you prefer to define the array without using the macro, that's exactly equivalente. Do what it feels better for you :). That's the nice part of having alternatives: everyone can use their preferred option ;).
Powered by SMFPacks Menu Editor Mod