Beispiel #1
0
/////////////////////////////////////////////////////////////////
// setTile
//    Sets a new value (0 or 1) for a concrete tile of the map.
// Coordinates are used to calculate the location of the tile
// in the map bitarray.
//
void map_setTile(u8 x, u8 y, u8 value) {
   // 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;
   
   // Set the new value for (x,y) tile in the bitarray
   cpct_setBit(map, value, tile_index);
}
Beispiel #2
0
//
// Bit Arrays Example: Main
//
void main (void) {
  u8 i, j;       // Counters for loops
  u8 array1[10]; // Array of 10 bytes, 80 bits, to be used bit by bit
  u8 array2[20]; // Array of 20 bytes, 160 bits, 80 groups of 2 bits.
  u8 array4[40]; // Array of 40 bytes, 320 bits, 80 groups of 4 bits.

  // Disable firmware to prevent it from restoring video mode or
  // interfering with our drawChar functions
  cpct_disableFirmware();

  // Set mode 2 for visual clarity on arrays printed
  cpct_setVideoMode(2);

  // 
  // Main Loop: loop forever showing arrays
  //
  while(1) {
    // First, erase all contents of our 3 arrays,
    // setting all their bits to 0
    cpct_memset(array1, 0, 10);
    cpct_memset(array2, 0, 20);
    cpct_memset(array4, 0, 40);

    //
    // Test 1: Set to 1 each bit on the array1 individually (all others to 0)
    //
    for (i = 0; i < 80; ++i) {
      // Set Bit i to 1
      cpct_setBit(array1, i, 1);

      // Print the complete array at the top of the screen
      printArray((u8*)0xC000, array1, 80, f_getbit); 
      
      // Reset again the bit to 0 an iterate
      cpct_setBit(array1, i, 0);
    }

    //
    // Test 2: Fill in the array2 with individual values from 3 to 1 
    //              (all the rest should be 0)
    //
    for (j = 3; j > 0; --j) { 
      for (i = 0; i < 80; ++i) {
        // Set the index i to the value j (1 to 3)
        cpct_set2Bits(array2, i, j);

        // Print the complete array
        printArray((u8*)0xC0A0, array2, 80, f_get2bits);

        // Reset the value of the item to 0 again
        cpct_set2Bits(array2, i, 0);
      }
    }

    //
    // Test 3: Fill in the array4 with consecutive elements from 0 to 15,
    //         16 times, rotating all the 16 elements through all the positions
    //         in the array.
    //
    for (j = 0; j < 16; j++) { 
      for (i = 0; i < 80; ++i) {
        // Increment value using loop indexes and calculate module 16 (AND 0x0F)
        u8 value = (i + j) & 0x0F;

        // Set next 4-bits element (i) to the calculated value and print the array
        cpct_set4Bits(array4, i, value);
        printArray((u8*)0xC140, array4, 80, f_get4bits);
      }
    }

    //
    // Test 4: Fill the array1 with 1's
    //
    for (i = 0; i < 80; ++i) {
      // Set next bit i to 1  
      cpct_setBit(array1, i, 1);

      // Print the complete array1 again
      printArray((u8*)0xC000, array1, 80, f_getbit); 
    }

    //
    // Test 5: Fill the array2 with 3's, then with 2's and then with 1's
    //
    for (j = 3; j > 0; --j) { 
      for (i = 0; i < 80; ++i) {
        // Set next bit i to j (3, 2, 1)  
        cpct_set2Bits(array2, i, j);

        // Print the complete array again
        printArray((u8*)0xC0A0, array2, 80, f_get2bits); 
      }
    }
  }
}