
#include "RCX_String.h"
#include "RCX_Control.h"
#include "H8.h" 
#include "Time.h"
#include "LCD.h"
#include "Battery.h"
#include "Buttons.h"

#include "RCX_Interrupts.h"

/* Interrupt handler for Run button */

static int16 Count;

void RunInt (void) 
{
  asm("push r0
       push r1
       push r2
       push r3
       push r4
       push r5
      ");

  Count = Count + 2;

  asm("pop  r5
       pop  r4
       pop  r3
       pop  r2
       pop  r1
       pop  r0
      ");
}	

void OnOffBreak (void)
{
  BusyPauseMS(3000);
  lcd_show_icon(LCD_STANDING);
  Count = Count + 4;
}

void _start(void) 
{ 

  lcd_show_int16(BatteryLevel());
  lcd_show_icon(LCD_STANDING);
  while ( ! Run );
  while (   Run );
  lcd_show_icon(LCD_WALKING); 

  Count = 0;
  lcd_show_int16(Count);
  BusyPauseMS(1000);

  RunInt();
  
  /* Make RunInt the interrupt handler for the Run button (IRQ0) */
  /* Generate interrupt by the falling edge of Run button (IRQ0) */
  /* Enable Run button interrupts (IRQ0 interrupts)              */

  IRQ0_Interrupt_Handler = RunInt; 
  ISCR = 3;                      
  IER  = 3;

  IRQ1_Interrupt_Handler = OnOffBreak;


  while ( ! View ){
     
     lcd_show_int16(Count);
     if ( Count > 10 ){
        Count = 0;
     }
  }

  RCX_Reset();

}	
