home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / cellsim / v2_5 / cm2 / cm_cell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-26  |  6.4 KB  |  258 lines

  1. /*****
  2.  *
  3.  * File: cm_cell.h
  4.  *   By: Dave Hiebeler
  5.  *       August 1989
  6.  *
  7.  * Header file for most of the CM Cellsim files
  8.  *
  9.  *****/
  10.  
  11. /*
  12.  *
  13.  * Cellsim copyright 1989, 1990 by Chris Langton and Dave Hiebeler
  14.  * (cgl@lanl.gov, hiebeler@heretic.lanl.gov)
  15.  *
  16.  * This package may be freely distributed, as long as you don't:
  17.  * - remove this notice
  18.  * - try to make money by doing so
  19.  * - prevent others from copying it freely
  20.  * - distribute modified versions without clearly documenting your changes
  21.  *   and notifying us
  22.  *
  23.  * Please contact either of the authors listed above if you have questions
  24.  * or feel an exception to any of the above restrictions is in order.
  25.  *
  26.  * If you make changes to the code, or have suggestions for changes,
  27.  * let us know!  If we use your suggestion, you will receive full credit
  28.  * of course.
  29.  */
  30.  
  31. /*****
  32.  * Cellsim history:
  33.  *
  34.  * Cellsim was originally written on Apollo workstations by Chris Langton.
  35.  *
  36.  * Sun versions:
  37.  *
  38.  * - version 1.0
  39.  *   by C. Ferenbaugh and C. Langton
  40.  *   released 09/02/88
  41.  *
  42.  * - version 1.5
  43.  *   by Dave Hiebeler and C. Langton  May - June 1989
  44.  *   released 07/03/89
  45.  *
  46.  * - version 2.0
  47.  *   by Dave Hiebeler and C. Langton  July - August 1989
  48.  *   never officially released (unofficially released 09/08/89)
  49.  *
  50.  * - version 2.5
  51.  *   by Dave Hiebeler and C. Langton  September '89 - February 1990
  52.  *   released 02/26/90
  53.  *****/
  54.  
  55.  
  56. /*****
  57.  *
  58.  * Includes, typedefs
  59.  *
  60.  *****/
  61.  
  62. #include <stdio.h>
  63. #include <math.h>
  64. #include <sys/wait.h>
  65. #include <sys/types.h>
  66. #include <sys/stat.h>
  67. #include <cm/paris.h>
  68. #include <cm/cmfb.h>
  69. #include "cm_cellproto.h"
  70. #include "sock_rtns.h"
  71.  
  72. typedef unsigned char byte;
  73. typedef void ((*void_func_ptr)());
  74. typedef byte ((*func_ptr)());
  75.  
  76.  
  77.  
  78. /*****
  79.  *
  80.  * Global vars
  81.  *
  82.  *****/
  83.  
  84. int
  85.     B, L, S, N, R, TSIZE, AMASK, nhood,
  86.     array_size, function, parm1, parm2,
  87.     phase, SOCKET_INUSE,
  88.     CM_disp_interval, use_FB, use_Sun_disp, CM_delay, forever_flag,debug2;
  89.  
  90. unsigned int
  91.     max_index;    /* max index into LT shared-array on CM */
  92.  
  93. int ns, debug;    /* socket fd and debug-level */
  94.  
  95. FILE *logfile;
  96.  
  97. unsigned char
  98.     *grid, *table,    /* array and table on CMFE */
  99.     red[256], green[256], blue[256];    /* for making cmap */
  100.  
  101.  
  102. void_func_ptr
  103.     initialization_function;
  104.  
  105. func_ptr
  106.     update_function, exit_function;
  107.  
  108. int (*auto_step)();
  109. void (*probe_func)();
  110.  
  111.  
  112. /*****
  113.  *
  114.  * Some defines
  115.  *
  116.  *****/
  117.  
  118. /*** neighborhood types ***/
  119. #define NH_VONN        1
  120. #define NH_MOORE    2
  121. #define NH_MARG        4
  122. #define NH_LIN        8
  123.  
  124. /*** Handy definitions for doing NEWS operations on CM ***/
  125. #define North 1, CM_downward
  126. #define South 1, CM_upward
  127. #define East 0, CM_upward
  128. #define West 0, CM_downward
  129.  
  130. /*** Definitions for getting single NEWS coordinates ***/
  131. #define VERTICAL 1
  132. #define HORIZONTAL 0
  133.  
  134.  
  135. /*****
  136.  *
  137.  * Various CM-related variables
  138.  *
  139.  *****/
  140.  
  141. /* Various fields used (probably not all of these are necessary;
  142.  * the code hasn't been very optimized for memory-usage yet).
  143.  */
  144. CM_field_id_t
  145.     cell, temp_value, trans, nbor_values, table_index, one,
  146.     bottom, not_bottom,
  147.     tmp_north, tmp_south, tmp_east,
  148.     tmp_west, tmp_nw, tmp_sw, tmp_ne, tmp_se,
  149.     VNorth, VSouth, VEast, VWest, VCenter,
  150.     MNorth, MSouth, MEast, MWest, MCenter, MNW, MSW, MNE, MSE,
  151.     LR1_L, LR1_C, LR1_R,
  152.     LR2_LL, LR2_L, LR2_C, LR2_R, LR2_RR,
  153.     LR3_LLL, LR3_LL, LR3_L, LR3_C, LR3_R, LR3_RR, LR3_RRR,
  154.     MargCcw, MargOpp, MargCw, MargCenter, MargPhase,
  155.     UL, UR, LR, LL, rand_num;
  156.  
  157. /*** Misc stuff ***/
  158. unsigned int geo_array[31];
  159. CM_vp_set_id_t vp_set;
  160. CM_geometry_id_t geo;
  161.  
  162. struct CMFB_display_id disp_id;
  163. CMFB_display_id_t FB_attach_ret_val;
  164.  
  165.  
  166. /*** Offsets into the word that holds the neighors of each cell ***/
  167. #define V_W_OFF 4
  168. #define V_C_OFF 3
  169. #define V_E_OFF 2
  170. #define V_N_OFF 1
  171. #define V_S_OFF 0
  172.  
  173. #define M_NW_OFF 8
  174. #define M_W_OFF 7
  175. #define M_SW_OFF 6
  176. #define M_N_OFF 5
  177. #define M_C_OFF 4
  178. #define M_S_OFF 3
  179. #define M_NE_OFF 2
  180. #define M_E_OFF 1
  181. #define M_SE_OFF 0
  182.  
  183. #define MARG_C_OFF 4
  184. #define MARG_CCW_OFF 3
  185. #define MARG_OPP_OFF 2
  186. #define MARG_CW_OFF 1
  187. #define MARG_PHASE_OFF 0
  188.  
  189. #define LR1_L_OFF 2
  190. #define LR1_C_OFF 1
  191. #define LR1_R_OFF 0
  192.  
  193. #define LR2_LL_OFF 4
  194. #define LR2_L_OFF 3
  195. #define LR2_C_OFF 2
  196. #define LR2_R_OFF 1
  197. #define LR2_RR_OFF 0
  198.  
  199. #define LR3_LLL_OFF 6
  200. #define LR3_LL_OFF 5
  201. #define LR3_L_OFF 4
  202. #define LR3_C_OFF 3
  203. #define LR3_R_OFF 2
  204. #define LR3_RR_OFF 1
  205. #define LR3_RRR_OFF 0
  206.  
  207.  
  208. /*** macros to look up neighbors ***/
  209. /* Von-N */
  210. #define VGetNorth CM_get_from_news_1L(VNorth,cell,North,L)
  211. #define VGetSouth CM_get_from_news_1L(VSouth,cell,South,L)
  212. #define VGetEast  CM_get_from_news_1L(VEast,cell,East,L)
  213. #define VGetWest  CM_get_from_news_1L(VWest,cell,West,L)
  214. #define VGetCenter CM_u_move_1L(VCenter,cell,L);
  215.  
  216. /* Linear, radius=1 */
  217. #define LR1GetL CM_get_from_news_1L(LR1_L, cell, West, L)
  218. #define LR1GetC CM_u_move_1L(LR1_C, cell, L)
  219. #define LR1GetR CM_get_from_news_1L(LR1_R, cell, East, L)
  220.  
  221. /* Linear, radius=2 */
  222. #define LR2GetL CM_get_from_news_1L(LR2_L, cell, West, L)
  223. #define LR2GetC CM_u_move_1L(LR2_C, cell, L)
  224. #define LR2GetR CM_get_from_news_1L(LR2_R, cell, East, L)
  225. /* After calling above macros, then the following 2 will work */
  226. #define LR2GetLL CM_get_from_news_1L(LR2_LL, LR2_L, West, L);
  227. #define LR2GetRR CM_get_from_news_1L(LR2_RR, LR2_R, East, L);
  228.  
  229. /* Linear, radius=3 */
  230. #define LR3GetL CM_get_from_news_1L(LR3_L, cell, West, L)
  231. #define LR3GetC CM_u_move_1L(LR3_C, cell, L)
  232. #define LR3GetR CM_get_from_news_1L(LR3_R, cell, East, L)
  233. /* After calling above macros, then the following 2 will work */
  234. #define LR3GetLL CM_get_from_news_1L(LR3_LL, LR3_L, West, L);
  235. #define LR3GetRR CM_get_from_news_1L(LR3_RR, LR3_R, East, L);
  236. /* After calling the above, these last 2 will work */
  237. #define LR3GetLLL CM_get_from_news_1L(LR3_LLL, LR3_LL, West, L);
  238. #define LR3GetRRR CM_get_from_news_1L(LR3_RRR, LR3_RR, East, L);
  239.  
  240. /* Moore */
  241. #define MGetCenter CM_u_move_1L(MCenter,cell,L);
  242. #define MGetNorth CM_get_from_news_1L(MNorth,cell,North,L)
  243. #define MGetSouth CM_get_from_news_1L(MSouth,cell,South,L)
  244. #define MGetEast  CM_get_from_news_1L(MEast,cell,East,L)
  245. #define MGetWest  CM_get_from_news_1L(MWest,cell,West,L)
  246. /* Note -- before you can use the following 4 macros, you must
  247.  * have called the above 4 macros!
  248.  */
  249. #define MGetNW    CM_get_from_news_1L(MNW,MNorth,West,L);
  250. #define MGetSW    CM_get_from_news_1L(MSW,MSouth,West,L);
  251. #define MGetNE    CM_get_from_news_1L(MNE,MNorth,East,L);
  252. #define MGetSE    CM_get_from_news_1L(MSE,MSouth,East,L);
  253.  
  254. /* Note that looking up Margolus nbors is a bit more tricky,
  255.  * so that is implemented as a function instead of macros.
  256.  */
  257.  
  258.