///////////////////////////////////////////////////////////////// // drawTile // Draws only one of the tiles of the map, given its coordinates. // It calculates the location in the screen of the given tile and // gets its actual value from the map array. Then it draws the // tile to the screen. // void map_drawTile(u8 x, u8 y) { // Calculate screen location where tile should be drawn u8 *pmem = cpct_getScreenPtr(map_base_location, x, y*TILE_HEIGHT); // Select appropriate colour pattern for the tile // (YELLOW for walls, BLACK for background) u8 c_pattern = cpct_px2byteM1(C_BLACK, C_BLACK, C_BLACK, C_BLACK); if (map_getTile(x, y) != 0) c_pattern = cpct_px2byteM1(C_YELLOW, C_YELLOW, C_YELLOW, C_YELLOW); // Draw the tile as a solid box cpct_drawSolidBox(pmem, c_pattern, TILE_WIDTH, TILE_HEIGHT); }
// 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); }