/*
 *  Copyright 2009 OpenSourceStewardshipFoundation.org
 *  Licensed under GNU General Public License version 2
 *
 * Author: seanhalle@yahoo.com
 *
 * Created on November 15, 2009, 2:35 AM
 */


#include <malloc.h>
#include <stdlib.h>


#include "SimParams.h"


uint8 *
read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName );


void
fill_sim_params_from_bag( SimulationParams *simParams, ParamBag *paramBag )
 { char *guestAppFileName, *systemCodeFileName;
   int numBytesInGuestApp, numBytesInSystemCode;
   
      ParamStruc *param;

      //param = getParamFromBag( "GuestApplicationFileName", paramBag );
   guestAppFileName = param->strValue;

      //param = getParamFromBag( "numBytesInGuestApp", paramBag );
   numBytesInGuestApp = param->intValue;

   simParams->guestApp =
    read_Machine_Code_From_File( numBytesInGuestApp, guestAppFileName );

      //param = getParamFromBag( "SystemCodeFileName", paramBag );
   systemCodeFileName = param->strValue;

      //param = getParamFromBag( "numBytesInSystemCode", paramBag );
   numBytesInSystemCode = param->intValue;

   simParams->systemCode =
    read_Machine_Code_From_File( numBytesInSystemCode, systemCodeFileName );

      //param = getParamFromBag( "numNodes", paramBag );
   simParams->numNodes = param->intValue;
 }


uint8 *
read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName )
 { int byte;
   FILE  *file;
   char  *machineCode = malloc( numBytesInFile );
   if( machineCode == NULL ) printf( "\nno mem for machine code\n" );

   file = fopen( machineCodeFileName, "r" );
   if( file == NULL ) { printf( "\nCouldn't open file!!\n"); exit(1);}

   fseek( file, 0, SEEK_SET );
   for( byte = 0; byte < numBytesInFile; byte++ )
    {
      if( feof( file ) )  printf( "file ran out too soon" );
//      machineCode[byte] = getchar( file );
    }
   return machineCode;
 }


//==========================================================================
void
printSimResults( SimulationResults simResults )
 { 
 }

