📄 cfunc.mod
字号:
/* retrieve entire base_address bits integer... */ base = states->bits[bit_index]; /* for each offset, mask off the bits and determine values */ cm_bits_mask_and_retrieve(base,bit_offset,out);}/*==============================================================================FUNCTION cm_store_bits_value()AUTHORS 23 Jul 1991 Jeffrey P. MurrayMODIFICATIONS 30 Sep 1991 Jeffrey P. MurraySUMMARY The following routine retrieves four-bit data from short integer array "bits". The integers are assumed to be at least two bytes each, so each will hold four four- bit values. INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE NONEGLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== Static CM_STORE_BITS_VALUE ROUTINE ===*//************************************************* The following routine retrieves four-bit ** data from short integer array "bits". The ** integers are assumed to be at least two ** bytes each, so each will hold four four- ** bit values. ** ** Created 7/23/91 ** Last Modified 7/23/91 J.P.Murray *************************************************/static void cm_store_bits_value(State_Table_t *states,int index, int bit_number, int in_val){ int err, /* error index value */ int1, /* temp storage variable */ bit_index, /* bits base address at which word bits will be found */ bit_offset; /* offset from ram base address at which bit[0] of the required word can be found */ short base; /* variable to hold current base integer for comparison purposes. */ double double1, double2; /* holding variables for modf routine */ /* obtain offset value from word_number, word_width & bit_number */ int1 = index * states->num_outputs + bit_number; double1 = int1 / 4.0; modf(double1, &double2); bit_index = double2; bit_offset = int1 - (double2 * 4.0); /* retrieve entire base_address bits integer... */ base = states->bits[bit_index]; /* for each offset, mask off the bits and store values */ cm_bits_mask_and_store(&base,bit_offset,in_val); /* store modified base value */ states->bits[bit_index] = base; }/*==============================================================================FUNCTION cm_read_state_file()AUTHORS 15 Jul 1991 Jeffrey P. MurrayMODIFICATIONS 23 Jul 1991 Jeffrey P. Murray 30 Sep 1991 Jeffrey P. MurraySUMMARY The following routine reads the file *state_file, parses the file, and stores the values found there into the *state, *bits, *inputs and *next_state arrays. INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE Returns a status integer value.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== Static CM_READ_STATE_FILE ROUTINE ===*/ /*************************************************** The following routine reads the file ** *state_file, parses the file, and stores ** the values found there into the *state, ** *bits, *inputs and *next_state arrays. ** ** Created 7/15/91 ** Last Modified 7/23/91 J.P.Murray ***************************************************/static int cm_read_state_file(FILE *state_file,State_Table_t *states){ int i, /* indexing variable */ j, /* indexing variable */ num_tokens, /* number of tokens in a given string */ bit_index, /* index to which bits[] integer we are accessing */ bit_offset, /* index to which bit within the current bits[] integer we are accessing */ string_type, /* integer holding value corresponding to the type of input string obtained: 1 = HEADER => State Header string 2 = CONTINUATION => a continuation line... values of state and bits must be retreived from the previous string. */ int1; /* temporary holding variable */ Cnv_Token_Type_t type; /* variable for testing token type returned. */ char temp[MAX_STRING_SIZE], /* holding string variable for testing input from state.in */ *s, /* main string variable */ *base_address, /* storage location for base address of string. */ *token; /* a particular token from the string */ float number; /* holding variable for timepoint values */ double double1, /* temporary holding variable */ double2; /* temporary holding variable */ short bit_value, /* holding variable for value read from state.in file which needs to be stored */ base; /* holding variable for existing non-masked bits[] integer */ i = 0; s = temp; while ( fgets(s,MAX_STRING_SIZE,state_file) != NULL) { /* Test this string to see if it is whitespace... */ base_address = s; while(isspace(*s) || (*s == '*')) (s)++; if ( *s != '\0' ) { /* This is not a blank line, so process... */ s = base_address; if ( '*' != s[0] ) { /* Count up total number of tokens including \0... */ j = 0; type = CNV_STRING_TOK; while ( type != CNV_NO_TOK ) { token = CNVget_token(&s, &type); j++; } num_tokens = (j-1); /* Test the type of entry this number of tokens represents. Valid types are: a. State Header with state, bits, inputs and next_state entries...total tokens equals num_inputs + num_outputs + 3 (e.g. "5 0s 0s 0s 0 0 -> 6"). b. State continuation line with inputs and next_state only...total tokens equals num_inputs + 2. (e.g. " 0 1 -> 7"). */ if ( (3 + states->num_inputs + states->num_outputs) == num_tokens) { string_type = HEADER; } else { if ( (2 + states->num_inputs) == num_tokens) { string_type = CONTINUATION; } else { /* Number of tokens is incorrect */ return 1; } } /* reset s to beginning... */ s = base_address; /** Retrieve each token, analyze, and **/ /** store the state, bits, inputs & **/ /** next_state information. **/ if ( HEADER == string_type ) { /**** header type loop ****/ for (j=0; j<(states->num_inputs + states->num_outputs + 3); j++) { token = CNVget_token(&s, &type); if ( 0 == j ) { /* obtain state value... */ /* convert to a floating point number... */ cnv_get_spice_value(token,&number); states->state[i] = number; } else { /* obtain each bit value & set bits entry */ if ( states->num_outputs >= j ) { /* preset this bit location */ bit_value = 12; if (0 == strcmp(token,"0s")) bit_value = 0; if (0 == strcmp(token,"1s")) bit_value = 1; if (0 == strcmp(token,"Us")) bit_value = 2; if (0 == strcmp(token,"0r")) bit_value = 3; if (0 == strcmp(token,"1r")) bit_value = 4; if (0 == strcmp(token,"Ur")) bit_value = 5; if (0 == strcmp(token,"0z")) bit_value = 6; if (0 == strcmp(token,"1z")) bit_value = 7; if (0 == strcmp(token,"Uz")) bit_value = 8; if (0 == strcmp(token,"0u")) bit_value = 9; if (0 == strcmp(token,"1u")) bit_value = 10; if (0 == strcmp(token,"Uu")) bit_value = 11; /* if this bit was not recognized, return with an error */ if (12 == bit_value) { return 1; } else { /* need to store this value in the bits[] array */ cm_store_bits_value(states,i,(j-1),bit_value); } } else { /* obtain inputs info... */ if ( (states->num_outputs + states->num_inputs) >= j ) { /* preset this bit location */ bit_value = 3; if (0 == strcmp(token,"0")) bit_value = 0; if (0 == strcmp(token,"1")) bit_value = 1; if (0 == strcmp(token,"x")) bit_value = 2; if (0 == strcmp(token,"X")) bit_value = 2; /* if this bit was not recognized, return with an error */ if (3 == bit_value) { return 1; } else { /* need to store this value in the inputs[] array */ cm_store_inputs_value(states,i,(j-1),bit_value); } } else { /* obtain next_state value */ if ( (1 + states->num_outputs + states->num_inputs) == j ) { /* skip the "->" token */ } else { /* convert to a floating point number... */ cnv_get_spice_value(token,&number); states->next_state[i] = number; } } } } } } else { /**** continuation type loop ****/ /* set state value to previous state value */ states->state[i] = states->state[i-1]; /* set bits values to previous bits values */ for (j=0; j<states->num_outputs; j++) { /*** Retrieve the previous bit value ***? cm_get_bits_value(*states,i,j,&out); switch (out.state) { case ZERO: switch (out.strength) { case STRONG: bit_value = 0; break; case RESISTIVE: bit_value = 3; break; case HI_IMPEDANCE: bit_value = 6; break; case UNDETERMINED: bit_value = 9; break; } break; case ONE: switch (out.strength) { case STRONG: bit_value = 1; break; case RESISTIVE: bit_value = 4; break; case HI_IMPEDANCE: bit_value = 7; break; case UNDETERMINED: bit_value = 10; break; } break; case UNKNOWN: switch (out.strength) { case STRONG: bit_value = 2; break; case RESISTIVE: bit_value = 5; break; case HI_IMPEDANCE: bit_value = 8; break; case UNDETERMINED: bit_value = 11; break; } break; } /*** Store this bit value ***/ cm_store_bits_value(states,i,j,bit_value); } for (j=0; j<(2 + states->num_inputs); j++) { token = CNVget_token(&s, &type); if ( j < states->num_inputs ) { /* preset this bit location */ bit_value = 3; if (0 == strcmp(token,"0")) bit_value = 0; if (0 == strcmp(token,"1")) bit_value = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -