Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > HWSim > HWSim__PingPong__HWDef
view src/Application/SimParams.c @ 1:7566745e812a
Ideas starting to gel.. application part close to candidate form
author | Me@portablequad |
---|---|
date | Sat, 19 Nov 2011 17:58:21 -0800 |
parents | 8ea476474093 |
children | 648207f2e38f |
line source
1 /*
3 * Copyright 2009 OpenSourceStewardshipFoundation.org
5 * Licensed under GNU General Public License version 2
7 *
9 * Author: seanhalle@yahoo.com
11 *
13 * Created on November 15, 2009, 2:35 AM
15 */
19 #include <malloc.h>
21 #include <stdlib.h>
25 #include "SimParams.h"
27 #include "ParamHelper/Param.h"
33 uint8 *
35 read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName );
41 void
43 fill_sim_params_from_bag( SimulationParams *simParams, ParamBag *paramBag )
45 { char *guestAppFileName, *systemCodeFileName;
47 int numBytesInGuestApp, numBytesInSystemCode;
51 ParamStruc *param;
53 param = getParamFromBag( "GuestApplicationFileName", paramBag );
55 guestAppFileName = param->strValue;
57 param = getParamFromBag( "numBytesInGuestApp", paramBag );
59 numBytesInGuestApp = param->intValue;
63 simParams->guestApp =
65 read_Machine_Code_From_File( numBytesInGuestApp, guestAppFileName );
69 param = getParamFromBag( "SystemCodeFileName", paramBag );
71 systemCodeFileName = param->strValue;
73 param = getParamFromBag( "numBytesInSystemCode", paramBag );
75 numBytesInSystemCode = param->intValue;
79 simParams->systemCode =
81 read_Machine_Code_From_File( numBytesInSystemCode, systemCodeFileName );
87 param = getParamFromBag( "numNodes", paramBag );
89 simParams->numNodes = param->intValue;
93 }
101 uint8 *
103 read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName )
105 { int byte;
107 FILE *file;
109 char *machineCode = malloc( numBytesInFile );
111 if( machineCode == NULL ) printf( "\nno mem for machine code\n" );
115 file = fopen( machineCodeFileName, "r" );
117 if( file == NULL ) { printf( "\nCouldn't open file!!\n"); exit(1);}
121 fseek( file, 0, SEEK_SET );
123 for( byte = 0; byte < numBytesInFile; byte++ )
125 {
127 if( feof( file ) ) printf( "file ran out too soon" );
129 machineCode[byte] = getchar( file );
133 }
135 return machineCode;
137 }
143 //==========================================================================
145 void
147 printSimResults( SimulationResults simResults )
149 {
151 }