#include "RCX_RTE.h"
#include "Speaker.h"
#include "OutputPorts.h"

/* Buttons */
#define port4_addr  0xffb7
#define port4       *((volatile byte *) port4_addr)

#define OnOff       ! ( port4 & ( 1 << 1 ) )

void _start(void) 
{ 
  int16 p; int16 i;

  SpeakerInit();
  
  p=1; i=0;
  while ( ! OnOff ) {
    SpeakerPlay(p,5);
    SpeakerPlay(p*10,5);
    OutputPorts = p*10-i;
    while (i>3) {
      SpeakerPlay(i,5);
      i--;
    }    
    
    p = ( p > 25 ) ? 1 : p+1;
  }
  
  RCX_Reset();
}       
