Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > HWSim > HWSim__PingPong__HWDef
comparison src/Application/SimParams.c @ 0:8ea476474093
Initial add -- gobbeldegook
| author | Me@portablequad |
|---|---|
| date | Mon, 07 Nov 2011 16:03:01 -0800 |
| parents | |
| children | 7566745e812a |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:c3e737f946e7 |
|---|---|
| 1 /* | |
| 2 | |
| 3 * Copyright 2009 OpenSourceStewardshipFoundation.org | |
| 4 | |
| 5 * Licensed under GNU General Public License version 2 | |
| 6 | |
| 7 * | |
| 8 | |
| 9 * Author: seanhalle@yahoo.com | |
| 10 | |
| 11 * | |
| 12 | |
| 13 * Created on November 15, 2009, 2:35 AM | |
| 14 | |
| 15 */ | |
| 16 | |
| 17 | |
| 18 | |
| 19 #include <malloc.h> | |
| 20 | |
| 21 #include <stdlib.h> | |
| 22 | |
| 23 | |
| 24 | |
| 25 #include "SimParams.h" | |
| 26 | |
| 27 #include "ParamHelper/Param.h" | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 uint8 * | |
| 34 | |
| 35 read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName ); | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 void | |
| 42 | |
| 43 fill_sim_params_from_bag( SimulationParams *simParams, ParamBag *paramBag ) | |
| 44 | |
| 45 { char *guestAppFileName, *systemCodeFileName; | |
| 46 | |
| 47 int numBytesInGuestApp, numBytesInSystemCode; | |
| 48 | |
| 49 | |
| 50 | |
| 51 ParamStruc *param; | |
| 52 | |
| 53 param = getParamFromBag( "GuestApplicationFileName", paramBag ); | |
| 54 | |
| 55 guestAppFileName = param->strValue; | |
| 56 | |
| 57 param = getParamFromBag( "numBytesInGuestApp", paramBag ); | |
| 58 | |
| 59 numBytesInGuestApp = param->intValue; | |
| 60 | |
| 61 | |
| 62 | |
| 63 simParams->guestApp = | |
| 64 | |
| 65 read_Machine_Code_From_File( numBytesInGuestApp, guestAppFileName ); | |
| 66 | |
| 67 | |
| 68 | |
| 69 param = getParamFromBag( "SystemCodeFileName", paramBag ); | |
| 70 | |
| 71 systemCodeFileName = param->strValue; | |
| 72 | |
| 73 param = getParamFromBag( "numBytesInSystemCode", paramBag ); | |
| 74 | |
| 75 numBytesInSystemCode = param->intValue; | |
| 76 | |
| 77 | |
| 78 | |
| 79 simParams->systemCode = | |
| 80 | |
| 81 read_Machine_Code_From_File( numBytesInSystemCode, systemCodeFileName ); | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 param = getParamFromBag( "numNodes", paramBag ); | |
| 88 | |
| 89 simParams->numNodes = param->intValue; | |
| 90 | |
| 91 | |
| 92 | |
| 93 } | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 uint8 * | |
| 102 | |
| 103 read_Machine_Code_From_File( int numBytesInFile, char *machineCodeFileName ) | |
| 104 | |
| 105 { int byte; | |
| 106 | |
| 107 FILE *file; | |
| 108 | |
| 109 char *machineCode = malloc( numBytesInFile ); | |
| 110 | |
| 111 if( machineCode == NULL ) printf( "\nno mem for machine code\n" ); | |
| 112 | |
| 113 | |
| 114 | |
| 115 file = fopen( machineCodeFileName, "r" ); | |
| 116 | |
| 117 if( file == NULL ) { printf( "\nCouldn't open file!!\n"); exit(1);} | |
| 118 | |
| 119 | |
| 120 | |
| 121 fseek( file, 0, SEEK_SET ); | |
| 122 | |
| 123 for( byte = 0; byte < numBytesInFile; byte++ ) | |
| 124 | |
| 125 { | |
| 126 | |
| 127 if( feof( file ) ) printf( "file ran out too soon" ); | |
| 128 | |
| 129 machineCode[byte] = getchar( file ); | |
| 130 | |
| 131 | |
| 132 | |
| 133 } | |
| 134 | |
| 135 return machineCode; | |
| 136 | |
| 137 } | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 //========================================================================== | |
| 144 | |
| 145 void | |
| 146 | |
| 147 printSimResults( SimulationResults simResults ) | |
| 148 | |
| 149 { int r, c, numRows, numCols, rowsToPrint, colsToPrint, rowIncr, colIncr; | |
| 150 | |
| 151 float32 *matrixArray; | |
| 152 | |
| 153 | |
| 154 | |
| 155 numRows = rowsToPrint = matrix->numRows; | |
| 156 | |
| 157 numCols = colsToPrint = matrix->numCols; | |
| 158 | |
| 159 matrixArray = matrix->array; | |
| 160 | |
| 161 | |
| 162 | |
| 163 rowIncr = numRows/20; if(rowIncr == 0) rowIncr = 1;//20 to 39 rows printed | |
| 164 | |
| 165 colIncr = numCols/20; if(colIncr == 0) colIncr = 1;//20 to 39 cols printed | |
| 166 | |
| 167 for( r = 0; r < numRows; r += rowIncr ) | |
| 168 | |
| 169 { for( c = 0; c < numCols; c += colIncr ) | |
| 170 | |
| 171 { printf( "%3.1f | ", matrixArray[ r * numCols + c ] ); | |
| 172 | |
| 173 } | |
| 174 | |
| 175 printf("\n"); | |
| 176 | |
| 177 } | |
| 178 | |
| 179 } | |
| 180 | |
| 181 | |
| 182 |
