home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / cellsim / v2_5 / cm2 / cm_cllmr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-04  |  3.7 KB  |  173 lines

  1. /*
  2.  * File: cm_cellmoore.c
  3.  *   By: Dave Hiebeler
  4.  *       August 1989
  5.  *
  6.  * Cellsim, cellular automata simulator
  7.  *
  8.  * Routines for running moore neighbor rules
  9.  */
  10.  
  11.  
  12. #include "cm_cell.h"
  13.  
  14. /*
  15.  *
  16.  * Cellsim copyright 1989, 1990 by Chris Langton and Dave Hiebeler
  17.  * (cgl@lanl.gov, hiebeler@heretic.lanl.gov)
  18.  *
  19.  * This package may be freely distributed, as long as you don't:
  20.  * - remove this notice
  21.  * - try to make money by doing so
  22.  * - prevent others from copying it freely
  23.  * - distribute modified versions without clearly documenting your changes
  24.  *   and notifying us
  25.  *
  26.  * Please contact either of the authors listed above if you have questions
  27.  * or feel an exception to any of the above restrictions is in order.
  28.  *
  29.  * If you make changes to the code, or have suggestions for changes,
  30.  * let us know!  If we use your suggestion, you will receive full credit
  31.  * of course.
  32.  */
  33.  
  34. /*****
  35.  * Cellsim history:
  36.  *
  37.  * Cellsim was originally written on Apollo workstations by Chris Langton.
  38.  *
  39.  * Sun versions:
  40.  *
  41.  * - version 1.0
  42.  *   by C. Ferenbaugh and C. Langton
  43.  *   released 09/02/88
  44.  *
  45.  * - version 1.5
  46.  *   by Dave Hiebeler and C. Langton  May - June 1989
  47.  *   released 07/03/89
  48.  *
  49.  * - version 2.0
  50.  *   by Dave Hiebeler and C. Langton  July - August 1989
  51.  *   never officially released (unofficially released 09/08/89)
  52.  *
  53.  * - version 2.5
  54.  *   by Dave Hiebeler and C. Langton  September '89 - February 1990
  55.  *   released 02/26/90
  56.  *****/
  57.  
  58.  
  59.  
  60. int auto_m();
  61. void probe_m();
  62.  
  63.  
  64. /* set up nhood-dependent stuff */
  65. void
  66. set_params_m()
  67. {
  68.     N = 9;
  69.     auto_step = auto_m;
  70.     probe_func = probe_m;
  71. }
  72.  
  73.  
  74.  
  75. /*
  76.  *run for "steps" time-steps; if steps is -1, then keep running until
  77.  * the client says to stop
  78.  */
  79. auto_m(steps)
  80. int steps;
  81. {
  82.     int i, nsteps;
  83.     unsigned char buf[4];
  84.  
  85.     if (steps == -1) {
  86.     nsteps = 0;
  87.     while (1) {
  88.         /* do a non-blocking read to see if client said to stop */
  89.         if (read_from_sock(ns, buf, 1, ON, debug2) == 1)
  90.         return nsteps;
  91.         usleep(CM_delay);
  92.         CM_set_context();
  93.         MGetNorth;
  94.         MGetSouth;
  95.         MGetEast;
  96.         MGetWest;
  97.         MGetNW;
  98.         MGetSW;
  99.         MGetNE;
  100.         MGetSE;
  101.         MGetCenter;
  102.         if (function) {
  103.         update_function();
  104.         }
  105.         else {
  106.         CM_aref32_shared_2L(temp_value,trans,
  107.                     nbor_values+2,32,(L*N)-2,max_index);
  108.         /* Ok, temp_value now has 4 8-bit numbers in it.
  109.          * One of them is the L-bit # we want.  We now get it.
  110.          */
  111.         CM_array_ref(cell,temp_value,nbor_values,L,2,4,8);
  112.         }
  113.         if (!(nsteps%CM_disp_interval)) {
  114.         if (FB_attach_ret_val && use_FB)
  115.             CMFB_display_image();
  116.         }
  117.         nsteps++;
  118.     }
  119.     }
  120.     else {
  121.     for (i=0; i<steps; i++) {
  122.         usleep(CM_delay);
  123.         CM_set_context();
  124.         MGetNorth;
  125.         MGetSouth;
  126.         MGetEast;
  127.         MGetWest;
  128.         MGetNW;
  129.         MGetSW;
  130.         MGetNE;
  131.         MGetSE;
  132.         MGetCenter;
  133.         if (function) {
  134.         update_function();
  135.         }
  136.         else {
  137.         CM_aref32_shared_2L(temp_value,trans,
  138.                     nbor_values+2,32,(L*N)-2,max_index);
  139.         /* Ok, temp_value now has 4 8-bit numbers in it.
  140.          * One of them is the L-bit # we want.  We now get it.
  141.          */
  142.         CM_array_ref(cell,temp_value,nbor_values,L,2,4,8);
  143.         }
  144.         if (!(i%CM_disp_interval)) {
  145.         if (FB_attach_ret_val && use_FB)
  146.             CMFB_display_image();
  147.         }
  148.         if (SOCKET_INUSE)
  149.         count_states();
  150.     }
  151.     }
  152. }
  153.  
  154.     
  155. /*
  156.  * Look up a transition in the LT on the CM
  157.  */
  158. void
  159. probe_m(buf)
  160. unsigned char buf[];
  161. {
  162.     unsigned int j;
  163.  
  164.     j = buf[3] + buf[2]*256 + buf[1]*256*256 + buf[0]*256*256*256;
  165.     CM_u_move_constant_1L(nbor_values, j, L*N);
  166.     CM_aref32_shared_2L(temp_value, trans,
  167.             nbor_values+2, 32, (L*N)-2, max_index);
  168.     /* CM_u_move_zero_1L(cell8, 8); */
  169.     CM_array_ref(table_index, temp_value, nbor_values, L, 2, 4, 8);
  170.     buf[0] = CM_u_read_from_processor_1L(0, table_index, 8);
  171. }
  172.  
  173.