// // printArray // This function prints the contents of a bitarray as characters on the screen. // Value 0 is shown as '_' for visual clarity. Other values are shown as characters // [1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?]. // void printArray(u8* pvideomem, void *array, u8 nItems, TFunc thefunction) { u8 out = 0; // Value returned by getBit functions [0-15] u8 i; // Counter through the number of elements in the array u8 c; // Character to draw // Iterate through all the items in the array to print them one by one for (i = 0; i < nItems; ++i) { // Access the array using the function that has been told to us // in the parameter 'thefunction' switch(thefunction) { // Get element as a single bit (As return value could be anything, // we distinguish between 0 and >0, so out will finally be 0 or 1). case f_getbit: out = (cpct_getBit (array, i) > 0); break; // Get element as a pair of bits case f_get2bits: out = cpct_get2Bits(array, i); break; // Get element as a chunk of 4 bits case f_get4bits: out = cpct_get4Bits(array, i); break; } // Depending on the value got from getXBits function, calculate // the character we have to print. (0 = '_', >0 = '0' + out) if (out) c = '0' + out; else c = '_'; // Draw the character and point to the next byte in memory (next location // to draw a character, as 1 byte = 8 pixels in mode 2) cpct_drawCharM2(pvideomem, 1, c); pvideomem++; } }
///////////////////////////////////////////////////////////////// // getTile // Gets the value (0 or not-zero) of a concrete tile of the map. // Coordinates refer to the concrete tile being addressed and are // used to calculate the location of the tile in the map bitarray. // u8 map_getTile(u8 x, u8 y) { // The map has MAP_HEIGHT rows, and each row has MAP_WIDTH // tiles. Therefore, location (x,y) is y times MAP_WIDTH // elements plus x elements. u16 tile_index = y * MAP_WIDTH + x; // Get the value of the tile (x,y) from the bitarray and return it u8 tile_value = cpct_getBit(map, tile_index); return tile_value; }