#include <pic14regs.h>

/* configure the device -- see data sheet! */
static __code unsigned int __at(0x2007) _conf1 = 0x3FFF;
static __code unsigned int __at(0x2008) _conf2 = 0x3FFF;

/*
 * This is the routine that is jumped into from the RESET vector.
 * It should initialize all global and/or static variables to
 * power-on/reset defaults (see device/lib/pic/libsdcc/idata.c in
 * the sdcc sources), but may be redefined in the project.
 * You could #define main _sdcc_gsinit_startup, but make sure
 * this function never returns (as the return stack is empty)!
 */
#ifdef USE_OWN_GSINIT
void
_sdcc_gsinit_startup(void)
{
    while (1) {
        /* XXX: Setup global/static variables here! */
        __asm pagesel _main __endasm;
        __asm goto _main __endasm;
    } // while
}
#endif /* USE_OWN_GSINIT */

extern int foo(int b, int c);

int
bar(int a)
{
    int c;

    c = 2*a;
    a = foo(c, a);
    return (a+c);
}

void
main(void)
{
  unsigned char i;
  unsigned char j;

  PORTA = 0x00;
  TRISA = 0;  /* configure all pins of PORTA as (o)utputs */

  /* disable peripherals on PORTA pins -- check datasheet! */
  //ANSEL = 0x00;     /* all PORTA pins digital I/O (16f88x)*/
  ADCON1 = 0x06;    /* all PORTA pins digital I/O (16f87xA) */
  CMCON = 0x07;     /* disable comparators (16f87xA) */

  j = 0;

  while (1) {
    PORTA = j;
    ++j;

    for (i = 0; i < 200; i++) {
      // prevent the loop from being optimized out
      __asm __endasm;
    } // for
  } // while
}
