// // MAIN: Using keyboard to move a sprite example // void initialize() { u8* pvideomem; // Pointer to video memory // Disable firmware to prevent it from interfering with setPalette and setVideoMode cpct_disableFirmware(); // Set up the hardware palette using hardware colour values cpct_setPalette(g_palette, 16); cpct_setBorder(HW_BLACK); // Set video mode 0 (160x200, 16 colours) cpct_setVideoMode(0); // Draw floor. As cpct_drawSolidBox cannot draw boxes wider than 63 bytes // and Screen width is 80 bytes, we draw 2 boxes of SCR_W/2 (40 bytes) each pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 0, FLOOR_Y); cpct_drawSolidBox(pvideomem, FLOOR_COLOR, SCR_W/2, FLOOR_HEIGHT); pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, SCR_W/2, FLOOR_Y); cpct_drawSolidBox(pvideomem, FLOOR_COLOR, SCR_W/2, FLOOR_HEIGHT); // Draw instructions pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 20); cpct_drawStringM0(" Sprite Flip Demo ", pvideomem, 2, 0); pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 0, 34); cpct_drawStringM0("[Cursor]", pvideomem, 4, 0); pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, 40, 34); cpct_drawStringM0("Left/Right", pvideomem, 3, 0); }
// // MAIN: Keyboard check example // void main(void) { // 32 bits counter, to let it count passed 65536 (up to 4 Billions) u32 i; // Disable firmware to prevent it from interfering with setVideoMode cpct_disableFirmware(); // Convert palettes from firmware colour values to // hardware colours (which are used by cpct_setPalette) cpct_fw2hw(G_banner_palette, 16); cpct_fw2hw(G_logo_palette, 4); // Set the border white, using colour 0 from G_banner_palette // after converting the colours to hardware values cpct_setBorder(G_banner_palette[0]); // Infinite main loop while (1) { // Draw CPCtelera's Logo and wait for a while drawLogo(); for(i=0; i < WAITLOOPS; ++i); // Draw CPCtelera's Banner and wait for a while drawBanner(); for(i=0; i < WAITLOOPS; ++i); } }
///////////////////////////////////////////////////////////////// // initialize // Initialize this application when it starts. Disable firmware, // set the video mode and colours, and initialize map and cursor. // void initialize() { u8 *pmem; // Disable firmware to prevent it from restoring video mode or // interfering with our drawString functions cpct_disableFirmware(); // Set the video Mode to 1 (320x200, 4 colours) cpct_setVideoMode(1); // Use default colours except for palette index 0 (background). // Default colours are (Blue, Yellow, Cyan, Red), let's use // (Black, Yellow, Cyan, Red). Change only colour 0 and border. cpct_setPALColour(0, 0x14); cpct_setBorder(0x14); // Initialize Base Pointer of the map in video memory. This is // the place where the map will start to be drawn (0,0). This // location is (MAP_START_X, MAP_START_Y) with respect to CPCT_VMEM_START. pmem = cpct_getScreenPtr(CPCT_VMEM_START, MAP_START_X, MAP_START_Y); map_setBaseMem(pmem); // Set cursor at the top-left corner of the screen cursor_setLocation(0, 0); // Draw messages with instructions, the map and the cursor drawMessages(); map_draw(); cursor_draw(); }
////////////////////////////////////////////////////////////////////////////// // Initialization of the CPC // This function will be called once at the start of the program. After // that, it won't be required anymore. Therefore, its code will be placed at // 0x4000 to be used once and then removed when an image is written to // this second video buffer (0x4000-0x7FFF) /// void initializeCPC() { cpct_disableFirmware(); // Disable the firmware not to interfere with us cpct_setVideoMode(0); // Set mode 0 (160x200, 16 colours) cpct_setPalette(g_palette, 16); // Set colour palette cpct_setBorder(g_palette[0]); // Set the border with same colour used for background (0) // Set up the main video buffer (0xC000) with a message and all colours set up setUpVideoBuffer(VMEM_0, 0, "Main Screen Buffer", 6, 0); }
void initCPC() { cpct_disableFirmware(); cpct_fw2hw(g_palette,16); cpct_fw2hw(g_palette2,16); cpct_fw2hw(g_palette3,16); cpct_setPalette(g_palette,16); cpct_setBorder (g_palette[0]); cpct_setVideoMode(0); cpct_akp_musicInit(G_menu); // cpct_akp_SFXInit (G_menu); }
///////////////////////////////////////////////////////////////////////// // Initialization routine // Disables firmware, initializes palette and video mode and // draws the background // void initialization (){ cpct_disableFirmware(); // Disable firmware to prevent it from interfering cpct_setPalette(g_palette, 7); // Set palette using hardware colour values cpct_setBorder (g_palette[0]); // Set border colour same as background (0) cpct_setVideoMode(0); // Change to Mode 0 (160x200, 16 colours) // Set the internal tileset for drawing Tilemaps cpct_etm_setTileset2x4(g_tileset); // Draw the background tilemap cpct_etm_drawTilemap2x4_f(MAP_WIDTH_TILES, MAP_HEIGHT_TILES, CPCT_VMEM_START, g_background); }
// // EXAMPLE: Measuring free cycles after moving an sprite // void main(void) { u8 i; // Loop index u8 x=0, y=0; // Sprite coordinates (in bytes) u8* pvideomem = (u8*)0xC000; // Sprite initial video memory byte location (where it will be drawn) u16 avc = 0; // Available cycles until next VSYNC, after all main loop calculations // First, disable firmware to prevent it from intercepting our palette and video mode settings (and, // at the same time, winning some speed not having to process firmware code at every interrupt) cpct_disableFirmware(); // Set palette and Screen Border (transform firmware to hardware colours and then set them) cpct_fw2hw (G_palette, 4); cpct_setPalette(G_palette, 4); cpct_setBorder (G_palette[1]); // Ensure MODE 1 is set cpct_setVideoMode(1); // Main Loop while(1) { // First, wait VSYNC monitor signal to synchronize the loop with it. We'll start doing // calculations always at the same time (when VSYNC is first detected) cpct_waitVSYNC(); // Scan Keyboard and change sprite location if cursor keys are pressed cpct_scanKeyboard_f(); if (cpct_isKeyPressed(Key_CursorRight) && x < 80 - SPR_W) { x++; pvideomem++; } else if (cpct_isKeyPressed(Key_CursorLeft) && x > 0 ) { x--; pvideomem--; } if (cpct_isKeyPressed(Key_CursorUp) && y > 0 ) { pvideomem -= (y-- & 7) ? 0x0800 : 0xC850; } else if (cpct_isKeyPressed(Key_CursorDown) && y < 200 - SPR_H) { pvideomem += (++y & 7) ? 0x0800 : 0xC850; } // Draw the sprite at its new location on screen. // Sprite automatically erases previous copy of itself on the screen because it moves // 1 byte at a time and has a 0x00 border that overwrites previous colours on that place cpct_drawSprite(G_death, pvideomem, SPR_W, SPR_H); // Wait to next VSYNC signal, calculating the amount of free cycles (time we wait for VSYNC) // As documented on <cpct_count2VSYNC>, function returns number of loop iterations (L), and // cycles shall be calculated doing 22 + 34*L avc = 22 + 34 * cpct_count2VSYNC(); // Print 5 digits on the upper right corner of the screen, // with the amount of free cycles calculated in previous step. // Digits will be printed at screen locations (0xC046, 0xC048, 0xC04A, 0xC04C, 0xC04E) for(i=0; i<5; i++) { u8 digit = '0' + (avc % 10); cpct_drawCharM1_f((void*)(0xC04E - 2*i), 3, 0, digit); avc /= 10; } } }
// Initialization of the Amstrad CPC at the start of the application void initializeCPC() { // Disable firmware: we dont want it to interfere with our code cpct_disableFirmware(); // Set the function interruptHandler to be called on each interrupt. cpct_setInterruptHandler(interruptHandler); // Set the hardware palette (convert firmware colour values to hardware ones and set the palette) cpct_fw2hw(G_palette, 16); cpct_setPalette(G_palette, 16); // Descomentar estas tres lineas cuando tengamos paleta cpct_setBorder(G_palette[0]); // Change to Mode 0 (160x200, 16 colours) cpct_setVideoMode(0); }
///////////////////////////////////////////////////////////////////////////////// // Main application's code // void application(void) { // Screen tilemap TScreenTilemap scr = { 0, 0, { 0, 0, MAP_WIDTH, MAP_HEIGHT} }; // First show user messages showMessages(); // Initialize the application cpct_disableFirmware(); // Firmware must be disabled for this application to work cpct_setBorder(0x00); // Set the border colour gray and.. cpct_setPALColour(0, 0x14); // ...background black // VERY IMPORTANT: Before using EasyTileMap functions (etm), the internal // pointer to the tileset must be set. cpct_etm_setTileset2x4(g_tileset); // Indefinitely draw the tilemap, listen to user input, // do changes and draw it again while(1) { drawScreenTilemap(&scr); // Redraws the tilemap readKeyboardInput(&scr); // Waits for a user input and makes associated changes } }
///////////////////////////////////////////////////////////////////////////////// // Machine initialization code // void initialize_CPC() { // Initialize the application cpct_disableFirmware(); // Firmware must be disabled for this application to work cpct_setVideoMode(0); // Set Mode 0 (160x200, 16 Colours) cpct_setPalette(g_palette, 13); // Set Palette cpct_setBorder(HW_BLACK); // Set the border and background colours to black // VERY IMPORTANT: Before using EasyTileMap functions (etm), the internal // pointer to the tileset must be set. cpct_etm_setTileset2x4(g_tileset); // Clean up the screen cpct_memset(CPCT_VMEM_START, 0x00, 0x4000); // Draw the full tilemap for the first time cpct_etm_drawTileBox2x4(0, 0, // (X, Y) upper-left corner of the tilemap SCR_TILE_WIDTH, MAP_HEIGHT, // (Width, Height) of the Box to be drawn (all the screen) MAP_WIDTH, // Width of the full tilemap (which is wider than the screen) CPCT_VMEM_START, // Pointer to the start of video memory (upper-left corner of the // ...tilemap in the screen) g_tilemap); // Pointer to the first tile of the tilemap to be drawn (upper-left // ... corner of the tilemap viewport window) }