Beispiel #1
0
/////////////////////////////////////////////////////////////////
// draw
//    Draws the map completely. It displays a message down the
// screen while drawing to inform the user.
//
void map_draw() {
   static u8* const string = "Drawing Map";
   u8 x, y;
   u8* pmem; 

   // Draw a message down the screen to inform the user
   // that the map is drawing
   pmem = cpct_getScreenPtr(CPCT_VMEM_START, 30, 160);
   cpct_drawStringM1(string, pmem, C_BLACK, C_RED);

   // Draw the map tile by tile
   for(y=0; y < MAP_HEIGHT; y++) 
      for(x=0; x < MAP_WIDTH; x++) 
         map_drawTile(x, y);

   // Remove the message that was informing the user
   // (Drawing the string with background colour)
   cpct_drawStringM1(string, pmem, C_BLACK, C_BLACK);
}
Beispiel #2
0
void drawMessages() {
   u8 i;
   
   // Define the strings for the messages as an array to 
   // be able to draw them in a single loop
   static u8* const strings[NUM_MSGS] = { 
       "[Cursors]" ,"Move"
      ,"[Space]"   ,"Draw/Remove"
      ,"[Escape]"  ,"Clear" 
   };

   // Define the properties of the messages that will be drawn:
   // (x,y) location, Foreground colour (fg) and Background Colour (bg)
   static const u8 msg_prop[NUM_MSGS][4] = {
    //   x,  y,     fg,      bg
    //----------------------------
      { 20,  0, C_RED , C_BLACK },  // Message 0
      { 40,  0, C_BLUE, C_BLACK },  // Message 1
      { 20, 16, C_RED , C_BLACK },  // Message 2
      { 40, 16, C_BLUE, C_BLACK },  // Message 3
      { 20, 32, C_RED , C_BLACK },  // Message 4
      { 40, 32, C_BLUE, C_BLACK }   // Message 5
   };

   // Draw all messages in a single loop, using propertis of each message
   for(i=0; i < NUM_MSGS; i++) {
      u8* pmem; 

      // Get Location where next message should be drawn using 
      // message properties 0 and 1 (x and y coordinates)
      pmem = cpct_getScreenPtr(CPCT_VMEM_START, msg_prop[i][0], msg_prop[i][1]);

      // Draw the i-th message with colours from its properties 2 and 3 (fg, bg)
      cpct_drawStringM1(strings[i], pmem, msg_prop[i][2], msg_prop[i][3]);
   }
}
Beispiel #3
0
// This example is built at 0x8000, so we can page at 0x4000.
// See the build configuration.
void main(void) {
   u8* pvmem;  // Pointer to video memory
   u8* firstByteInPage = (u8*) 0x4000;
   u8 i;

   cpct_pageMemory(RAMCFG_0 | BANK_0);				// Not needed, sets the memory with the first 64kb accesible, in consecutive banks.
   // firstByteInPage point to address 0x4000. With this memory 
   // configuration, that is physical address 0x4000. 
   *firstByteInPage = cpct_px2byteM1(1, 1, 1, 1);	// Set the first byte in page to all pixels with colour 1 (yellow by default).

   cpct_pageMemory(RAMCFG_4 | BANK_0);				// Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   // RAMCFG_4: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_4, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3
   // firstByteInPage point to address 0x4000. With this memory 
   // configuration, 0x4000 is the first byte in BANK_0, RAM_4, 
   // which is physical address 0x10000. 
   *firstByteInPage = cpct_px2byteM1(2, 2, 2, 2);	// Set the first byte in page to all pixels with colour 2 (cyan by default ).

   cpct_pageMemory(RAMCFG_5 | BANK_0);				// Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   // RAMCFG_5: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_5, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3
   // firstByteInPage point to address 0x4000. With this memory 
   // configuration, 0x4000 is the first byte in BANK_0, RAM_5, 
   // which is physical address 0x14000. 
   *firstByteInPage = cpct_px2byteM1(3, 3, 3, 3);	// Set the first byte in page to all pixels with colour 3 (red by default ).

   cpct_pageMemory(RAMCFG_6 | BANK_0);				// Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   // RAMCFG_6: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_6, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3
   // firstByteInPage point to address 0x4000. With this memory 
   // configuration, 0x4000 is the first byte in BANK_0, RAM_6, 
   // which is physical address 0x18000. 
   *firstByteInPage = cpct_px2byteM1(1, 1, 2, 2);	// Set the first byte in page to all pixels with colours 1, 2 (yellow, cyan by default ).

   cpct_pageMemory(RAMCFG_7 | BANK_0);				// Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   // RAMCFG_7: 0000-3FFF -> RAM_0, 4000-7FFF -> RAM_7, 8000-BFFF -> RAM_2, C000-FFFF -> RAM_3
   // firstByteInPage point to address 0x4000. With this memory 
   // configuration, 0x4000 is the first byte in BANK_0, RAM_7, 
   // which is physical address 0x1C000. 
   *firstByteInPage = cpct_px2byteM1(1, 1, 3, 3);	// Set the first byte in page to all pixels with colours 1, 3 (yellow, cyan by default ).

   cpct_pageMemory(RAMCFG_0 | BANK_0); 				// Set the memory again to default state

   // Clear Screen
   cpct_memset(CPCT_VMEM_START, 0, 0x4000);

   // Let's make visible the values we stored.
   cpct_pageMemory(RAMCFG_0 | BANK_0); // Not needed, sets the memory with the first 64kb accesible, in consecutive banks.
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 0);
   cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8);
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 0);
   cpct_drawStringM1("RAMCFG_0", pvmem, 1, 0);

   cpct_pageMemory(RAMCFG_4 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 16);
   cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8);
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 16);
   cpct_drawStringM1("RAMCFG_4", pvmem, 1, 0);

   cpct_pageMemory(RAMCFG_5 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 32);
   cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8);
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 32);
   cpct_drawStringM1("RAMCFG_5", pvmem, 1, 0);

   cpct_pageMemory(RAMCFG_6 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 48);
   cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8);
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 48);
   cpct_drawStringM1("RAMCFG_6", pvmem, 1, 0);

   cpct_pageMemory(RAMCFG_7 | BANK_0); // Set the 4th page (64kb to 80kb) in 0x4000-0x7FFF
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 64);
   cpct_drawSolidBox(pvmem, *firstByteInPage, 2, 8);
   pvmem = cpct_getScreenPtr(CPCT_VMEM_START, 4, 64);
   cpct_drawStringM1("RAMCFG_7", pvmem, 1, 0);

   cpct_pageMemory(DEFAULT_MEM_CFG); // Equivalent to RAMCFG_0 | BANK_0 

   // Loop forever
   while (1);
}