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

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