예제 #1
0
파일: main.c 프로젝트: mattl/cpctelera
//
// printArray
//   This function prints the contents of a bitarray as characters on the screen.
// Value 0 is shown as '_' for visual clarity. Other values are shown as characters
// [1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?].
//
void printArray(u8* pvideomem, void *array, u8 nItems, TFunc thefunction) {
    u8 out = 0; // Value returned by getBit functions [0-15]
    u8 i;       // Counter through the number of elements in the array
    u8 c;       // Character to draw 

    // Iterate through all the items in the array to print them one by one
    for (i = 0; i < nItems; ++i) {

      // Access the array using the function that has been told to us 
      // in the parameter 'thefunction'
      switch(thefunction) {
        // Get element as a single bit (As return value could be anything, 
        // we distinguish between 0 and >0, so out will finally be 0 or 1).
        case f_getbit:   out = (cpct_getBit (array, i) > 0); break;

        // Get element as a pair of bits 
        case f_get2bits: out = cpct_get2Bits(array, i); break;

        // Get element as a chunk of 4 bits
        case f_get4bits: out = cpct_get4Bits(array, i); break;
      }
      // Depending on the value got from getXBits function, calculate
      // the character we have to print. (0 = '_', >0 = '0' + out)
      if (out) 
        c = '0' + out;
      else
        c = '_';

      // Draw the character and point to the next byte in memory (next location
      // to draw a character, as 1 byte = 8 pixels in mode 2)
      cpct_drawCharM2(pvideomem, 1, c);
      pvideomem++;
    }
}
예제 #2
0
////////////////////////////////////////////////////////////////////////
// MAIN: Arkos Tracker Music Example
//    Keys:
//       * SPACE - Start / Stop Music
//       *   1   - Play a sound effect on Channel A
//       *   2   - Play a sound effect on Channel C
//
void main(void) {
   TKeyStatus k_space, k_0, k_1;    // Status of the 3 Keys for this example (Space, 1, 2)
   u8  playing   = 1;               // Flag to know if music is playing or not
   u8  color     = 1;               // Color to draw charactes (normal / inverse)
   u8* pvideomem = CPCT_VMEM_START; // Pointer to video memory where next character will be drawn

   // All 3 keys are considered to be released at the start of the program
   k_space = k_0 = k_1 = K_RELEASED;

   // Initialize CPC
   cpct_disableFirmware(); // Disable firmware to prevent interaction
   cpct_setVideoMode(2);   // Set Mode 2 (640x200, 2 colours)

   // Initialize the song to be played
   cpct_akp_musicInit(molusk_song);    // Initialize the music
   cpct_akp_SFXInit(molusk_song);      // Initialize instruments to be used for SFX (Same as music song)

   while (1) {
      // We have to call the play function 50 times per second (because the song is 
      // designed at 50Hz). We only have to wait for VSYNC and call the play function
      // when the song is not stopped (still playing)
      cpct_waitVSYNC();

      // Check if the music is playing. When it is, do all the things the music
      // requires to be done every 1/50 secs.
      if (playing) {
         cpct_akp_musicPlay();   // Play next music 1/50 step.

         // Write a new number to the screen to see something while playing. 
         // The number will be 0 when music is playing, and 1 when it finishes.
         //  -> If some SFX is playing write the channel where it is playing
         
         // Check if there is an instrument plaing on channel A
         if (cpct_akp_SFXGetInstrument(AY_CHANNEL_A))
            cpct_drawCharM2(pvideomem, color, 'A'); // Write an 'A' because channel A is playing
         
         // Check if there is an instrument plaing on channel C
         else if (cpct_akp_SFXGetInstrument(AY_CHANNEL_C))
            cpct_drawCharM2(pvideomem, color, 'C'); // Write an 'C' because channel A is playing 
         
         // No SFX is playing on Channels A or C, write the number of times
         // this song has looped.
         else
            cpct_drawCharM2(pvideomem, color, '0' + cpct_akp_songLoopTimes);

         // Point to the start of the next character in video memory
         if (++pvideomem >= (u8*)0xC7D0) {
            pvideomem = CPCT_VMEM_START; // When we reach the end of the screen, we return..
            color ^= 1;                  // .. to the start, and change the colour
         }

         // Check if music has already ended (when looptimes is > 0)
         if (cpct_akp_songLoopTimes > 0)
            cpct_akp_musicInit(molusk_song); // Song has ended, start it again and set loop to 0
      }

      // Check keyboard to let the user play/stop the song with de Space Bar
      // and reproduce some sound effects with keys 1 and 0
      cpct_scanKeyboard_f();

      // When Space is released, stop / continue music
      if ( checkKeyEvent(Key_Space, &k_space) == K_RELEASED ) {
         // Only stop it when it was playing previously
         // No need to call "play" again when continuing, as the
         // change in "playing" status will make the program call "play"
         // again from the next cycle on
         if (playing)
            cpct_akp_stop();
         
         // Change it from playing to not playing and viceversa (0 to 1, 1 to 0)
         playing ^= 1;

      // Check if Key 0 has been released to reproduce a Sound effect on channel A
      } else if ( checkKeyEvent(Key_0, &k_0) == K_RELEASED ) {
         cpct_akp_SFXPlay(13, 15, 36, 20, 0, AY_CHANNEL_A);

      // Check if Key 1 has been released to reproduce a Sound effect on channel C
      } else if ( checkKeyEvent(Key_1, &k_1) == K_RELEASED ) 
         cpct_akp_SFXPlay(3, 15, 60, 0, 40, AY_CHANNEL_C);
   }
}