home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / cellsim / v2_5 / src / cellscr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-01  |  11.3 KB  |  472 lines

  1. /*****
  2.  *
  3.  *
  4.  * File: cellscr.h
  5.  *
  6.  * Cellular automata simulator
  7.  * Includes, definitions, and variable declarations/definitions.
  8.  *
  9.  *
  10.  *****/
  11.  
  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.  
  59. /*****
  60.  *
  61.  * Includes
  62.  *
  63.  *****/
  64.  
  65. #include <pixrect/pixrect_hs.h>
  66. #include <suntool/sunview.h>
  67. #include <suntool/panel.h>
  68. #include <suntool/canvas.h>
  69. #include <varargs.h>
  70. #include <fcntl.h>
  71. #include <sys/types.h>
  72. #include <sys/stat.h>
  73. #include "cell.def"
  74. /* #include "cell.param" */
  75.  
  76.  
  77. /*****
  78.  *
  79.  * Defines
  80.  *
  81.  *****/
  82.  
  83. #define POP_DISP_LEN 32
  84. #define pan_lmargin 10
  85. #define pan_lvalue 70
  86. #define pan_2nd_lmargin 100
  87. #define pan_2nd_lvalue 160
  88. #define pan_hspace 100
  89. #define pan_tmargin 10
  90. #define pan_vspace 20
  91. #define pan_ncols 2
  92. #define NUM_MSGS 8
  93. #define pan_small_hspace 80
  94. #define pan_small_ncols 3
  95.  
  96. #define MODE_EDIT    0
  97. #define MODE_PROBE    1
  98. #define MODE_PLANEEDIT    2
  99.  
  100. /* colormap stuff */
  101. #define CLEN 8                /* length in bits of one color value */
  102. #define CMASK 0xFF            /* mask of CLEN bits */
  103. #define CMAPLEN 256            /* length of colormap */
  104.  
  105.  
  106.  
  107. /*****
  108.  *
  109.  * Typedefs
  110.  *
  111.  *****/
  112.  
  113. typedef unsigned char ((*func_ptr)());
  114. typedef unsigned char byte;
  115.  
  116.  
  117. /*****
  118.  *
  119.  * Functions callable from the control panel
  120.  *
  121.  *****/
  122.  
  123. /*** Run menu ***/
  124. extern int
  125.     run_proc(), skip_run_proc(), bound_run_proc(), sb_run_proc(),
  126.     screenful_proc(), step_proc(), skip_proc(), run_local_proc(),
  127.     step_local_proc();
  128.  
  129. /*** Defaults menu ***/
  130. int
  131.     toggle_save_in_image_dir_proc(), toggle_save_images_compressed(),
  132.     toggle_auto_image_change_proc(), toggle_save_in_LT_dir_proc(),
  133.     toggle_save_LT_compressed(), toggle_auto_nhood_change_proc(),
  134.     toggle_save_in_cmap_dir_proc(), FB_toggle(), Sun_disp_toggle();
  135.  
  136. extern int
  137.     set_image_dir(), set_table_dir(), set_fcn_dir(), set_cmap_dir(),
  138.     CM_change_host(),
  139.     CM_change_port(), CM_change_delay_proc(), CM_disp_interval_proc(),
  140.     CM_image_dir_proc(), CM_fcn_dir_proc(), CM_LT_dir_proc(),
  141.     CM_set_zoom(), CM_set_pan(),
  142.     change_stuff_proc(), change_image_size_proc(), chdir_proc();
  143.     
  144.  
  145. /*** Image menu ***/
  146. extern int
  147.     iload(), isave_proc(), iload_resize(), isave_resize(),
  148.     isave_raster(), iload_CAM6(), isave_CAM6(), ienter(), iclear(),
  149.     iswap(), icopy(), iinvert();
  150.  
  151. /*** Rules menu ***/
  152. extern int
  153.     load_rule(), tsave_proc(), tclear_proc(), talter(),
  154.     tgenerate(), lambda_proc(), lambda_step_proc(),
  155.     rho_proc(), edit_parm1(), edit_parm2();
  156. int
  157.     tsymmetry();
  158.  
  159. /*** Buffer menu ***/
  160. extern int
  161.     bload(), bsave(), bswap(), bxor(), bor(), band();
  162.  
  163. /*** Clear menu ***/
  164. extern int
  165.     clear_proc(), CM_clear(), zero_proc();
  166.  
  167. /*** Learn menu ***/
  168. extern int
  169.     learn_proc();
  170.  
  171. /*** Set menu ***/
  172. extern int
  173.     set_proc();
  174.  
  175. /*** Zoom menu ***/
  176. extern int
  177.     zoom_proc(), magnify_proc();
  178.  
  179. /*** Closeup menu ***/
  180. extern int
  181.     closeup_proc();
  182.  
  183. /*** Zoom in & out menus */
  184. extern int
  185.     zoom_in_proc(), zoom_out_proc();
  186.  
  187. /*** Draw menu ***/
  188. extern int
  189.     quick_random_proc(), general_random_proc(), horiz_line_proc(),
  190.     vert_line_proc(), arb_line_proc(), hollow_circ_proc(), shaded_circ_proc();
  191.  
  192. /*** Color menu ***/
  193. int
  194.     cmap_load(), cmap_save_proc(), cmap_alter();
  195.  
  196. /*** Planes menu ***/
  197. int
  198.     plane_reset_proc(), plane_display_proc();
  199. extern int
  200.     pclear(), pinvert();
  201.  
  202. /*** CM menu ***/
  203. extern int
  204.     CM_connect(), CM_send_image(), CM_get_image_proc(), CM_send_LT(),
  205.     CM_send_cmap(), CM_disconnect(), CM_load_image_proc(),
  206.     CM_load_rule_proc(), CM_quick_random_proc(), CM_general_random_proc();
  207.  
  208. /*** Sequence menu ***/
  209. extern int
  210.     sequence1_proc(), sequence2_proc(), sequence3_proc(), sequence4_proc(),
  211.     sequence5_proc();
  212.  
  213. /*** Quit menu ***/
  214. int
  215.     quit_proc();
  216.  
  217. /*** Shift buttons ***/
  218. extern int
  219.     right_proc(), left_proc(), up_proc(), down_proc(), shift_proc();
  220.  
  221.  
  222. /*****
  223.  *
  224.  * Various external functions
  225.  *
  226.  *****/
  227. extern int
  228.     CM_set_displays(),
  229.     add_sequence(),
  230.     expand_fname();
  231.  
  232.  
  233. /*****
  234.  *
  235.  * External variables
  236.  *
  237.  *****/
  238.  
  239. extern byte
  240.     save_images_compressed, save_LT_compressed;
  241.  
  242. extern byte
  243.     *ca;
  244.  
  245. extern struct pixrect
  246.     *ca_handle;
  247.  
  248. extern int
  249.     stime,
  250.     closeup, side, MAXSIZE, xstart, ystart, table_symmetry, mag,
  251.     save_in_image_dir, save_in_LT_dir, save_in_cmap_dir,
  252.     use_FB, use_Sun_disp, blackwhite, saved_mag_factor,
  253.     use_CM, drawing, function, saved_xinc, saved_yinc,
  254.     CM_zoom, CM_delay, CM_panx, CM_pany;
  255.  
  256. extern short
  257.     AMASK, ABASE, NHOOD, B, S, L, R, stop_on_mode, setting_sequence;
  258.  
  259. extern unsigned short
  260.     CM_port;
  261.  
  262. extern char
  263.     saved_rule_file[], saved_image_file[], Image_dir[], Table_dir[],
  264.     Fcn_dir[], Cmap_dir[], CM_hostname[], CM_image_dir[], CM_fcn_dir[],
  265.     CM_LT_dir[];
  266.  
  267.  
  268.  
  269. /*****
  270.  *
  271.  * Local routines
  272.  *
  273.  *****/
  274.  
  275. static int
  276.     defaults_image_menu_proc(), defaults_rule_menu_proc(),
  277.     defaults_cmap_menu_proc(), defaults_CM_menu_proc(),
  278.     mode_proc(), stop_on_proc(), screen_event_proc(),
  279.     do_first_item_proc(), button_event_proc(), menu_notify_proc();
  280. int
  281.     display_image();    /* well, this is visible to other modules as well */
  282.  
  283. static int
  284.     def_im_popup_proc(), def_rule_popup_proc(), def_cmap_popup_proc(),
  285.     def_CM_popup_proc();
  286. static void
  287.     def_im_done_proc(), def_rule_done_proc(), def_cmap_done_proc(),
  288.     def_CM_done_proc(), CM_send_zoom_proc(), CM_send_panx_proc(),
  289.     CM_send_pany_proc();
  290.  
  291. /*****
  292.  *
  293.  * Local variables
  294.  *
  295.  *****/
  296.  
  297. static Frame
  298.     frame, popup, def_im_popup, def_rule_popup, def_cmap_popup, def_CM_popup;
  299.  
  300. static Canvas
  301.     canvas;
  302.  
  303. static Pixwin
  304.     *pw, *window_pw, *panel_pw;
  305.  
  306. static struct pixrect
  307.     *tmpmag = NULL;
  308.  
  309. static Panel
  310.     panel, pop_panel, def_im_panel, def_rule_panel, def_cmap_panel,
  311.     def_CM_panel;
  312.  
  313. static Panel_item
  314.     defaults_button, pan_time, pan_pos, pan_state, pan_planes, pan_mode,
  315.     pan_msg[NUM_MSGS], pan_stop_on, pop_input,
  316.     def_im_save_item, def_im_compress_item, def_im_imagedir_item,
  317.     def_im_autochange_item,
  318.     def_rule_save_item, def_rule_compress_item, def_rule_tabledir_item,
  319.     def_rule_fcndir_item, def_rule_autochange_item,
  320.     def_cmap_save_item, def_cmap_compress_item, def_cmap_cmapdir_item,
  321.     def_CM_host_item, def_CM_port_item, def_CM_rundelay_item,
  322.     def_CM_display_item, def_CM_imagedir_item, def_CM_fcndir_item,
  323.     def_CM_LTdir_item, def_CM_zoom_item, def_CM_panx_item, def_CM_pany_item,
  324.     def_im_2Dalways_item;
  325.  
  326. static Panel_setting
  327.     return_proc();
  328.  
  329. static Menu
  330.     rules_menu, defaults_menu, image_menu, CM_menu,
  331.     defaults_image_menu, defaults_rule_menu, defaults_fcn_menu,
  332.     defaults_cmap_menu, defaults_CM_menu, edit_menu, probe_menu,
  333.     planeedit_menu;
  334.  
  335. static Inputmask
  336.     frame_mask, panel_mask, canvas_mask;
  337.  
  338. static int
  339.     saved_cmap_entry = 0, curr_color = 1, msg_line = 0, curr_planemask = 1,
  340.     screen_mode = MODE_EDIT, prow = 0, pcol = 0,
  341.     color[CMAPLEN], color2[CMAPLEN], rule_shown;
  342.  
  343. static char
  344.     saved_display_mask[BUFLEN],
  345.     saved_cmap_file[BUFLEN],
  346.     cmap_name[BUFLEN], cmap_name2[BUFLEN], cmap_name3[BUFLEN],
  347.     buf1[BUFLEN], buf2[BUFLEN];
  348.  
  349. byte save_cmap_compressed;
  350.  
  351. static Icon icon;
  352.  
  353.  
  354.  
  355. static byte
  356.     red[CMAPLEN], green[CMAPLEN], blue[CMAPLEN];
  357.  
  358.  
  359.  
  360. /*****
  361.  *
  362.  * Variables visible to other modules (globals)
  363.  *
  364.  *****/
  365.  
  366. int
  367.     auto_nhood_change, auto_image_change, use_2D_always;
  368.  
  369.  
  370. /*****
  371.  *
  372.  * Really ugly SunView stuff
  373.  *
  374.  *****/
  375.  
  376. static short icon_image[] = {
  377. #include "cell.icon"
  378. };
  379. mpr_static(icon_pixrect, 64, 64, 1, icon_image);
  380.  
  381. Cursor  cursor;                /* cursor variables */
  382. static short cursor_image[] = {
  383.     0x0000, 0x0000, 0x0000, 0x1818, 0x1818, 0x0660, 0x0660, 0x0180,
  384.     0x0180, 0x0660, 0x0660, 0x1818, 0x1818, 0x0000, 0x0000, 0x0000
  385. };
  386. mpr_static(cursor_pixrect, 16, 16, 1, cursor_image);
  387.  
  388.  
  389. static short texture_images[CMAPLEN][16] = {
  390.     {
  391. #include "t0.cursor"
  392.     }, {
  393. #include "t1.cursor"
  394.     }, {
  395. #include "t2.cursor"
  396.     }, {
  397. #include "t3.cursor"
  398.     }, {
  399. #include "t4.cursor"
  400.     }, {
  401. #include "t5.cursor"
  402.     }, {
  403. #include "t6.cursor"
  404.     }, {
  405. #include "t7.cursor"
  406.     }, {
  407. #include "t8.cursor"
  408.     }, {
  409. #include "t9.cursor"
  410.     }, {
  411. #include "t10.cursor"
  412.     }, {
  413. #include "t11.cursor"
  414.     }, {
  415. #include "t12.cursor"
  416.     }, {
  417. #include "t13.cursor"
  418.     }, {
  419. #include "t14.cursor"
  420.     }, {
  421. #include "t15.cursor"
  422.     }
  423. };
  424.  
  425. struct mpr_data data[CMAPLEN] = {
  426.     {mpr_linebytes(16,1), (short *)texture_images[0], {0, 0}, 0, 0},
  427.     {mpr_linebytes(16,1), (short *)texture_images[1], {0, 0}, 0, 0},
  428.     {mpr_linebytes(16,1), (short *)texture_images[2], {0, 0}, 0, 0},
  429.     {mpr_linebytes(16,1), (short *)texture_images[3], {0, 0}, 0, 0},
  430.     {mpr_linebytes(16,1), (short *)texture_images[4], {0, 0}, 0, 0},
  431.     {mpr_linebytes(16,1), (short *)texture_images[5], {0, 0}, 0, 0},
  432.     {mpr_linebytes(16,1), (short *)texture_images[6], {0, 0}, 0, 0},
  433.     {mpr_linebytes(16,1), (short *)texture_images[7], {0, 0}, 0, 0},
  434.     {mpr_linebytes(16,1), (short *)texture_images[8], {0, 0}, 0, 0},
  435.     {mpr_linebytes(16,1), (short *)texture_images[9], {0, 0}, 0, 0},
  436.     {mpr_linebytes(16,1), (short *)texture_images[10], {0, 0}, 0, 0},
  437.     {mpr_linebytes(16,1), (short *)texture_images[11], {0, 0}, 0, 0},
  438.     {mpr_linebytes(16,1), (short *)texture_images[12], {0, 0}, 0, 0},
  439.     {mpr_linebytes(16,1), (short *)texture_images[13], {0, 0}, 0, 0},
  440.     {mpr_linebytes(16,1), (short *)texture_images[14], {0, 0}, 0, 0},
  441.     {mpr_linebytes(16,1), (short *)texture_images[15], {0, 0}, 0, 0}
  442. };
  443.  
  444.  
  445. static struct pixrect textures_pr[CMAPLEN] = {
  446.     {&mem_ops, 16, 16, 1, (caddr_t)&data[0]},
  447.     {&mem_ops, 16, 16, 1, (caddr_t)&data[1]},
  448.     {&mem_ops, 16, 16, 1, (caddr_t)&data[2]},
  449.     {&mem_ops, 16, 16, 1, (caddr_t)&data[3]},
  450.     {&mem_ops, 16, 16, 1, (caddr_t)&data[4]},
  451.     {&mem_ops, 16, 16, 1, (caddr_t)&data[5]},
  452.     {&mem_ops, 16, 16, 1, (caddr_t)&data[6]},
  453.     {&mem_ops, 16, 16, 1, (caddr_t)&data[7]},
  454.     {&mem_ops, 16, 16, 1, (caddr_t)&data[8]},
  455.     {&mem_ops, 16, 16, 1, (caddr_t)&data[9]},
  456.     {&mem_ops, 16, 16, 1, (caddr_t)&data[10]},
  457.     {&mem_ops, 16, 16, 1, (caddr_t)&data[11]},
  458.     {&mem_ops, 16, 16, 1, (caddr_t)&data[12]},
  459.     {&mem_ops, 16, 16, 1, (caddr_t)&data[13]},
  460.     {&mem_ops, 16, 16, 1, (caddr_t)&data[14]},
  461.     {&mem_ops, 16, 16, 1, (caddr_t)&data[15]}
  462. };
  463.     
  464.  
  465. #define two_item_cycle(panel, label, string1, string2, x, y) \
  466.    panel_create_item(panel,\
  467.    PANEL_CYCLE, PANEL_LABEL_STRING, label,\
  468.    PANEL_CHOICE_STRINGS, string1, string2, 0,\
  469.    PANEL_ITEM_X, ATTR_COL(x), PANEL_ITEM_Y, ATTR_ROW(y),\
  470.    0);
  471.  
  472.