/*  TT8 specific includes  */

#include        <TT8.h>                 /* Tattletale Model 8 Definitions */
#include        <tat332.h>              /* 68332 Tattletale (7,8) Hardware Definitions */
#include        <sim332.h>              /* 68332 System Integration Module Definitions */
#include        <qsm332.h>              /* 68332 Queued Serial Module Definitions */
#include        <tpu332.h>              /* 68332 Time Processing Unit Definitions */
#include        <dio332.h>              /* 68332 Digital I/O Port Pin Definitions */
#include        <tt8pic.h>              /* Model 8 PIC Parallel Slave Port Definitions */
#include        <tt8lib.h>              /* definitions and prototypes for Model 8 library */

/*  general C includes  */
#include        <stdio.h>
#include        <stdlib.h>
#include		<string.h>

//  includes related to the disk drive
#include		<pcdisk.h>

//  includes for the data logger
#include		"assert.h"
#include		"eeprom.h"

//  Not actually used in the setup program, but necessary in order to link in the
//  logdisk routines.
char wd[EMAXPATH] = "A:\\";
const long DISK_FREQ = (long)8e6;

int main (int argc, char** argv)  {
	int answer;

	InitTT8(NO_WATCHDOG, TT8_TPU);  //  setup Model 8 for running C programs
	SimSetFSys(6e6);				//  currently run at 6 MHz
	SerSetBaud(9600,0);				//  reset baud after every clock change
	printf ("I print, therefore I am.\n");

	//  read the current values of the eeprom
	printf ("The current value of the setup data is:\n");
	if (eeprom_read_setup_data (0) != 0)  {
		printf ("Couldn't read data.  The defaults would be:\n");
		eeprom_print_setup_data ();
		return 0;
	}
	eeprom_print_setup_data ();

	//  reset setup data to defaults
	printf ("The default values are:\n");
	eeprom_set_default_setup_data ();
	eeprom_print_setup_data ();
	
	if (SerByteAvail ())
		answer = SerGetByte ();
	printf ("Do you want to write the defaults to the EEPROM? ");
	fflush (stdout);
	answer = SerGetByte ();
	printf ("%c\n", (char)answer);
	if (answer != 'y')
		return 0;
		
	//  write data and read it back to verify
	if (eeprom_write_setup_data (0) != 0)  {
		printf ("Couldn't write - quitting.\n");
		return 0;
	}	

	//  zero the current data just in case the read fails
	memset (&setup_data, 0, sizeof(setup_data));
	//  read and print the setup data so we can verify that it
	//  was properly written to eeprom	
	printf ("\nRead as:\n");
	if (eeprom_read_setup_data (0) != 0)  {
		printf ("Oops - couldn't read.\n");
		return 0;
	}
	eeprom_print_setup_data ();
	ResetToMon ();
	return 0;
}
	
	
//  This subroutine spoofs a routine which is used by the normal logger program,
//  but which is unused for the setup.  It is easier to resolve the external reference
//  here than it is to include the science logger and all its required code
//
void sci_logger_setup_partition (void)  {
	return;
}	
	