#include "tt7rmlib.h"
#include "rovcal.h"
#include <timing.h>

void TPuts(char *str);

/*******************************************************/

int tt7init(void){

  return 0;

} /*tt7init()*/



/********************************************************
	   Auxilliary Output Port Routine

In: Port number (1-4), 1 or 0 to set or clear bits in port, output
    byte (0 to FF).
Return: Void

The routine first checks to see if the port is the high byte
of the 16 bit port word.  If it is, it adds FF to the byte.
The routine then sets or clears bits depending upon the variable
"setclear".
**********************************************************/

void outport(short port, short setclear, unsigned short outdata) {

  static short int port1data, port2data;

  if(port==2 || port==4) outdata = outdata << 8;

  if(port==1 || port==2) {
    if(setclear) port1data = port1data | outdata;
    else port1data = port1data & !outdata;

    printf("\nPort 1 and 2 data = %X", port1data); /* OUT0-OUT15 */
    return;
  }

  if(port==3 || port==4) {
    if(setclear) port2data = port2data | outdata;
    else port2data = port2data & !outdata;

    printf("\nPort 3 and 4 data = %X", port2data);   /* OUT16-OUT31 */
  }
  return;
}

/********************************************************
	 Auxilliary Input Port Routine

In: Number of port bit to be tested.
Return: Value of tested bit (0 or 1).

The routine clears all bits in the input word except the
one of interest.  It then compares the two words: if they are
equal, then the bit of interest must have been a one.
*********************************************************/

int inport(unsigned short portbit) {

  unsigned short portword;

  if(kbhit()) return 0;
    else return 1;

}

/********************************************************/

void reset(void) {

  exit(0);

}

/********************************************************/

void DelayMilliSecs(unsigned long mS) {

  unsigned long t1, t2;

  for(t1=1; t1<mS; ++t1) {
    for(t2=1; t2<1000; ++t2);
  }
}

/********************************************************/

float battvoltage(void) {

  return 32760*BATTVOLTCAL;
}

/*************************************/

float syscurrent(void) {

  return 21135*SYSCURRCAL;
}

/*************************************/

float gfvoltage(void) {

  return 32760*GFVOLTCAL;
}

/**************************************/

float tilt_x(void) {

  return (15561-16380)*TILTXCAL;
}

/**************************************/

float tilt_y(void) {

  return (17199-16380)*TILTYCAL;
}

/**************************************/

int heading(void) {

  char headstring[4];
  int heading;

  printf("Enter Heading: ");
  gets(headstring);
  heading = atoi(headstring);
  printf("\nHeading: %d", heading);
  return heading;
}

/**************************************/

float speed(void) {
  return 10.1;
}

/********************************************************/

void TPuts(char *str) {
  puts(str);
  return;
}

/********************************************************/
long MilliSecs(void) {

  return 1000;
}
/********************************************************/