Example #1
0
//
// 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);
}
Example #2
0
//////////////////////////////////////////////////////////////////////////////
// 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);
}
Example #3
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);
}
Example #4
0
/////////////////////////////////////////////////////////////////////////
// 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 #5
0
//
// 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;
      }
   }
}
Example #6
0
// 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);

}
Example #7
0
//
// Draw CPCtelera's Logo (Mode 1)
//
void drawLogo() {
    // Pointer to video memory location where the logo will be drawn
    u8* pvideo;

    // Clear the screen filling it up with 0's
    cpct_clearScreen_f64(0);

    // Set Mode 1 Logo palette and change to Mode 1
    cpct_setPalette(G_logo_palette, 4);
    cpct_setVideoMode(1);     

    // Draw CPCtelera's Logo as one unique sprite 160x191 pixels (40x191 bytes in mode 1)
    // Remember: in Mode 1, 1 byte = 4 pixels    

    // Draw the sprite at screen byte coordinates (20, 4) (pixel coordinates (80, 4))
    pvideo = cpct_getScreenPtr(SCR_VMEM, 20, 4);
    cpct_drawSprite(G_CPCt_logo, pvideo, LOGO_W, LOGO_H);
}
Example #8
0
//
// MAIN: Using keyboard to move a sprite example
//
void main(void) {
   u8  x=10, y=10;   // Sprite coordinates
   u8* pvideomem;    // Pointer to video memory

   //
   // Set up the screen
   //
   // Disable firmware to prevent it from interfering with setPalette and setVideoMode
   cpct_disableFirmware();

   // Set the colour palette
   cpct_fw2hw     (G_palette, 4); // Convert our palette from firmware to hardware colours 
   cpct_setPalette(G_palette, 4); // Set up the hardware palette using hardware colours
   
   // Set video mode 1 (320x200, 4 colours)
   cpct_setVideoMode(1);

   // 
   // Infinite moving loop
   //
   while(1) {
      // Scan Keyboard (fastest routine)
      // The Keyboard has to be scanned to obtain pressed / not pressed status of
      // every key before checking each individual key's status.
      cpct_scanKeyboard_f();

      // Check if user has pressed a Cursor Key and, if so, move the sprite if
      // it will still be inside screen boundaries
      if      (cpct_isKeyPressed(Key_CursorRight) && x < (SCR_W - SP_W) ) ++x; 
      else if (cpct_isKeyPressed(Key_CursorLeft)  && x > 0              ) --x; 
      if      (cpct_isKeyPressed(Key_CursorUp)    && y > 0              ) --y;
      else if (cpct_isKeyPressed(Key_CursorDown)  && y < (SCR_H - SP_H) ) ++y;
      
      // Get video memory byte for coordinates x, y of the sprite (in bytes)
      pvideomem = cpct_getScreenPtr(CPCT_VMEM_START, x, y);

      // Draw the sprite in the video memory location got from coordinates x, y
      cpct_drawSprite(G_spriteLogoCT, pvideomem, SP_W, SP_H);
   }
}
Example #9
0
/////////////////////////////////////////////////////////////////////////////////
// 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)
}
Example #10
0
//
// Draw CPCtelera's Squared Banner (Mode 0)
//
void drawBanner() {
    // Video memory pointers for the 2 sprites that form the Squared banner
    u8 *pvideo_s1, *pvideo_s2;

    // Clear the screen filling it up with 0's
    cpct_clearScreen_f64(0);

    // Set Mode 0 Squared Banner palette and change to Mode 0
    cpct_setPalette  (G_banner_palette, 16);
    cpct_setVideoMode(0);

    // Draw CPCtelera's Squared Banner in 2 parts of 80x96 pixels (40x96 bytes in mode 0)
    // We have to draw it in two parts because cpct_drawSprite function cannot 
    // draw sprites wider than 63 bytes. 
    // Remember: in Mode 0, 1 byte = 2 pixels

    // Draw left part at screen byte coordinates  ( 0, 52) (pixel coordinates ( 0, 52))
    pvideo_s1 = cpct_getScreenPtr(SCR_VMEM,  0, 52);
    cpct_drawSprite(G_CPCt_left,  pvideo_s1, BANNER_W, BANNER_H);

    // Draw right part at screen byte coordinates (40, 52) (pixel coordinates (80, 52))
    pvideo_s2 = cpct_getScreenPtr(SCR_VMEM, 40, 52);
    cpct_drawSprite(G_CPCt_right, pvideo_s2, BANNER_W, BANNER_H);
}