📄 cfunc.mod
字号:
/* $Id: cfunc.mod,v 1.4 2005/08/23 08:21:01 pnenzi Exp $ *//*.......1.........2.........3.........4.........5.........6.........7.........8================================================================================FILE d_ram/cfunc.modCopyright 1991Georgia Tech Research Corporation, Atlanta, Ga. 30332All Rights ReservedPROJECT A-8503-405 AUTHORS 23 Aug 1991 Jeffrey P. MurrayMODIFICATIONS 30 Sep 1991 Jeffrey P. Murray SUMMARY This file contains the model-specific routines used to functionally describe the d_ram code model.INTERFACES FILE ROUTINE CALLED CMevt.c void *cm_event_alloc() void *cm_event_get_ptr() REFERENCED FILES Inputs from and outputs to ARGS structure. NON-STANDARD FEATURES NONE===============================================================================*//*=== INCLUDE FILES ====================*/#include <stdio.h>#include <ctype.h>#include <math.h>#include <string.h> /*=== CONSTANTS ========================*/#define MASK0 0x0003#define MASK1 0x000c#define MASK2 0x0030#define MASK3 0x00c0#define MASK4 0x0300#define MASK5 0x0c00#define MASK6 0x3000#define MASK7 0xc000/*=== MACROS ===========================*/ /*=== LOCAL VARIABLES & TYPEDEFS =======*/ /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ /*==============================================================================FUNCTION cm_address_to_decimal()AUTHORS 27 Jun 1991 Jeffrey P. MurrayMODIFICATIONS 8 Jul 1991 Jeffrey P. Murray 30 Sep 1991 Jeffrey P. MurraySUMMARY Calculates a decimal value from binary values passed.INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE A pointer containing the total (*total).GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== CM_ADDRESS_TO_DECIMAL ROUTINE ===*//************************************************* The following routine calculates a ** decimal value equivalent to the binary ** value passed to it on address[i] bits. ** The determined value is written to the ** integer *total. ** ** Created 6/27/91 J.P.Murray *************************************************/static int cm_address_to_decimal(Digital_State_t *address,int address_size,int *total){ int i, /* indexing variable */ multiplier, /* binary multiplier value */ err; /* error value: 1 => output is unknown 0 => output is valid */ err = 0; *total = 0; multiplier = 1; for (i=0; i<address_size; i++) { if ( UNKNOWN == address[i] ) { err = 1; break; } else { if (address[i] == ONE) { *total += multiplier; } } multiplier *= 2; } return err; }/*==============================================================================FUNCTION cm_mask_and_store()AUTHORS 8 Jul 1991 Jeffrey P. MurrayMODIFICATIONS 30 Sep 1991 Jeffrey P. MurraySUMMARY Masks and stores a two-bit value into a passed short pointer, using an offset value. This effectively handles storage of eight two-bit values into a single short integer space in order to conserve memory.INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE Returns updated *base value.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== CM_MASK_AND_STORE ROUTINE ===*//************************************************* The following routine masks and stores ** the value passed to it by the out value ** by masking the appropriate bits in the ** base integer. The particular bit affected ** is determined by the ram_offset value. ** ** Created 7/8/91 J.P.Murray *************************************************/static int cm_mask_and_store(short *base,int ram_offset,Digital_State_t out){ switch (ram_offset) { case 0: if ( ZERO == out ) { *base = *base & ~(MASK0); } else { if (ONE == out) { *base = *base & 0xfffd; *base = *base | 0x0001; } else { *base = *base & 0xfffe; *base = *base | 0x0002; } } break; case 1: if ( ZERO == out ) { *base = *base & ~(MASK1); } else { if (ONE == out) { *base = *base & 0xfff7; *base = *base | 0x0004; } else { *base = *base & 0xfffb; *base = *base | 0x0008; } } break; case 2: if ( ZERO == out ) { *base = *base & ~(MASK2); } else { if (ONE == out) { *base = *base & 0xffdf; *base = *base | 0x0010; } else { *base = *base & 0xffef; *base = *base | 0x0020; } } break; case 3: if ( ZERO == out ) { *base = *base & ~(MASK3); } else { if (ONE == out) { *base = *base & 0xff7f; *base = *base | 0x0040; } else { *base = *base & 0xffbf; *base = *base | 0x0080; } } break; case 4: if ( ZERO == out ) { *base = *base & ~(MASK4); } else { if (ONE == out) { *base = *base & 0xfdff; *base = *base | 0x0100; } else { *base = *base & 0xfeff; *base = *base | 0x0200; } } break; case 5: if ( ZERO == out ) { *base = *base & ~(MASK5); } else { if (ONE == out) { *base = *base & 0xf7ff; *base = *base | 0x0400; } else { *base = *base & 0xfbff; *base = *base | 0x0800; } } break; case 6: if ( ZERO == out ) { *base = *base & ~(MASK6); } else { if (ONE == out) { *base = *base & 0xdfff; *base = *base | 0x1000; } else { *base = *base & 0xefff; *base = *base | 0x2000; } } break; case 7: if ( ZERO == out ) { *base = *base & ~(MASK7); } else { if (ONE == out) { *base = *base & 0x7fff; *base = *base | 0x4000; } else { *base = *base & 0xbfff; *base = *base | 0x8000; } } break; }return 0;}/*==============================================================================FUNCTION cm_mask_and_retrieve()AUTHORS 8 Jul 1991 Jeffrey P. MurrayMODIFICATIONS 30 Sep 1991 Jeffrey P. MurraySUMMARY This is a companion function to cm_mask_and_store(). Masks off and retrieves a two-bit value from a short integer word passed to the function, using an offset value. This effectively handles retrieval of eight two-bit values from a single short integer space in order to conserve memory.INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE Returns updated *base value.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== CM_MASK_AND_RETRIEVE ROUTINE ===*//*************************************************** The following routine masks and retrieves ** the value passed to it by the out value ** by masking the appropriate bits in the ** base integer. The particular bit affected *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -