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

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