
/* TT7PCLIB.C

Tattletale Mod. 7 Library Functions Modified for PC Compatibility */
#include "tt7pclib.h"
#include "tserial.h"
#include <cport.h>

long g_sim_tick_rate = 1000;
COM comport;

/************************************************************/

short AtoDReadWord(short chan){

  chan++;
  return 16380;

}

/************************************************************/

void DelayMilliSecs(unsigned long mS){

  delay(mS);
  return;

}

/************************************************************/

DriveErr DFDrivePrep(void){

  return;
}
/************************************************************/

DriveErr DriveReady(bool waitReady){

  return;
}

/************************************************************/

DriveErr DFRead(ptr dfStart, short dfNum){

  return;
}
/************************************************************/

bool DFSetSize(ptr dfSize, short dfCount){

  return 0;
}

/************************************************************/

DriveErr DFWrite( ptr dfStart, short dfNum){

  return;
}

/*************************************************************/

DriveErr DriveOff(void){

  return;
}

/*************************************************************/

DriveErr DriveOn(bool waitReady){

  return;
}

/*************************************************************/

void DisableParIO(void){

  return;
}

/************************************************************/

long GetTickRate(void){

  return g_sim_tick_rate;
}

/************************************************************/

long MilliSecs(void){

  return (TensMilliSecs() * 10);
}

/************************************************************/

void PChange(char port, unsigned short pin){

  printf(" Pin %c%d Changed", port,pin);
  return;
}

/************************************************************/


void PClear(char port, unsigned short pin){
/*
  printf(" Pin %c%d Cleared", port,pin);
*/
  return;
}

/************************************************************/


int Pin(char port, unsigned short pin){

  printf(" Pin %c%d Checked", port,pin);
  return 0;
}

/************************************************************/

void PSMemFreeAll(void){

  return;
}

/*************************************************************/

void *PSMemAllocAll(long *psmemsize){

  *psmemsize = 1000;
  return malloc(1000);
}

/*************************************************************/

void *PSMemAlloc(int nblocks){

  return malloc(nblocks * 8);
}

/************************************************************/


ulong PSMemGetSize(SIZSEL sizsel){

  return 1;
}

/************************************************************/


void PSet(char port, unsigned short pin){
/*
  printf(" Pin %c%d Set", port,pin);
*/
  return;
}

/************************************************************/

void SerInFlush(void){

  while( kbhit() ) getch();
  return;
}

/************************************************************/

short SerGetByte(void)
{

  return (short)getch();
}

/************************************************************/

short SerGetByteLP(void){

  return (short)getch();
}

/************************************************************/

short SerTimedGetByte(register long msTimeout){

  return (short)getch();
}

/************************************************************/

void SerPutByte(ushort theByte){

  putch((int)theByte);
  return;
}

/************************************************************/

void SerPutStr(char *str){

  puts(str);
  return;
}

/************************************************************/

bool SerByteAvail(void){

  return (bool)kbhit();
}

/************************************************************/

bool SetTickRate(long tickRate){

  g_sim_tick_rate = tickRate;
  return 0;
}

/************************************************************/

bool Sleep(long ticks){
  int t;

  for(t=0; t<ticks; t++){
    DelayMilliSecs(1000/g_sim_tick_rate);
  }
  return 0;
}

/************************************************************/

long TensMilliSecs(void){
  struct time t;
  long tms;

  gettime(&t);
/*
  printf("\nHour: %d", t.ti_hour);
  printf("\nMin: %d", t.ti_min);
  printf("\nSec: %d", t.ti_sec);
  printf("\nMsec: %d", t.ti_hund);
*/
  tms = (long)(t.ti_hour)*360000 + (long)(t.ti_min)*6000
       + (long)(t.ti_sec)*100  + (long)(t.ti_hund);

return tms;

}

/************************************************************/

int TPUGetPin(short chan){

  return 1;
}


/**********************************************************/

void TPUSetPin(short chan, short pinval){

  return;
}

/************************************************************/

int TSerByteAvail(int chan){

  return ComLenRx(comport);
}

/************************************************************/

void TSerInFlush(int chan){

  ComFlushRx(comport);
  return;
}

/************************************************************/

int TSerGetByte(int chan){

  return ComGetc(comport);
}

/************************************************************/

int TSerOpen(int chan, int outflag, long qsize,
	long baud, int parity, int databits, int stopbits){

  if(outflag == INP) return 0;    // Don't open port twice

  comport = ComOpen(COM1, B9600, W8|S1|NONE, 1024, 512);
  if(comport == NULL){
    printf("\nError opening comport.");
    return 1;
  }
  return 0;
}

/************************************************************/

void TSerPutByte(int chan, int data){

  ComPutc(comport, data);
}

/************************************************************/

void SetTimeTM(struct tm *tp, vfptr sync){

  return;
}

/**************************************************************/

XmdmErr XmodemSendMem(void *address, long length, ushort timeout){

  return 0;
}

/**************************************************************/

void MonCmd(char *cmdstr){

  return;
}
