home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff331.lzh / CRobots / CRobots.doc < prev    next >
Text File  |  1990-03-21  |  60KB  |  1,562 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.      _____________________________________________________________
  13.     |                                                             |
  14.     |:                                                           :|
  15.     |    #####  ######  ####### ######  ####### #######  #####    |
  16.     |   #     # #     # #     # #     # #     #    #    #     #   |
  17.     |   #       #     # #     # #     # #     #    #    #         |
  18.     |   #       ######  #     # ######  #     #    #     #####    |
  19.     |   #       #   #   #     # #     # #     #    #          #   |
  20.     |   #     # #    #  #     # #     # #     #    #    #     #   |
  21.     |    #####  #     # ####### ######  #######    #     #####    |
  22.     |:                                                           :|
  23.     |_____________________________________________________________|
  24.  
  25.  
  26.                   ___                   ____      ___
  27.                  /   \    /\ /\    *   /    \    /   \
  28.                 /     \  /  V  \   _  |         /     \
  29.                 |     |  |     |  | | |     _   |     |
  30.                 |-----|  |     |  | | |      \  |-----|
  31.                 |     |  | |V| |  | | |       | |     |
  32.                 |     |  |_| |_|  |_|  \_____/  |     |
  33.  
  34.  
  35.  
  36.         (C) Copyright 1985, Tom Poindexter
  37.         (C) Copyright 1989-90, David Wright - Amiga Version
  38.  
  39.  
  40.            David Wright
  41.            4262 Bennington
  42.            Brunswick, OH 44212
  43.            (216) 273-1064
  44.            davewt@NCoast.ORG
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. Tom Poindexter '85                                      David Wright '89-90
  64.  
  65.  
  66.                            _1_.  _D_i_s_t_r_i_b_u_t_i_o_n _a_g_r_e_e_m_e_n_t_:
  67.  
  68.           You may  make copies of this program, manual, and other files and
  69.        give  them to your friends, upload it to bulletin boards, or include
  70.        it  in  the library of a non-profit computer club. In short, you are
  71.        free  to  distribute  at will with the exception of distribution for
  72.        profit.  
  73.  
  74.                                  _2_.  _I_n_t_r_o_d_u_c_t_i_o_n
  75.  
  76.        _2_-_1_.  _D_e_s_c_r_i_p_t_i_o_n 
  77.  
  78.           CRobots ("see-robots")  is  a game based on computer programming.
  79.        Unlike  arcade type games which require human input controlling some
  80.        object,  all  strategy in CRobots must be complete before the actual
  81.        game  begins.  Game  strategy is condensed into a C language program
  82.        that  you  design  and  write.  Your  program controls a robot whose
  83.        mission  is  to  seek  out,  track,  and  destroy other robots, each
  84.        running  different  programs. Each robot is equally equipped, and up
  85.        to  four  robots  may  compete at once. CRobots is best played among
  86.        several   people,  each  refining  their  own  robot  program,  then
  87.        matching program against program.  
  88.  
  89.           CRobots consists  of  a  C  compiler,  a  virtual  computer,  and
  90.        battlefield  display.  The  CRobots compiler accecpts a limited (but
  91.        useful)  subset  of  the C language. The robot programs are aided by
  92.        hardware  functions  to  scan  for  opponents,  start and stop drive
  93.        mechanisms,  fire  cannons, etc. After the programs are compiled and
  94.        loaded  into separate robots, the battle is observed. Robots moving,
  95.        missiles  flying  and  exploding, and certain status information are
  96.        displayed on the screen, in real-time.  
  97.  
  98.  
  99.        _2_-_2_.  _I_n_t_e_n_d_e_d _a_u_d_i_e_n_c_e 
  100.  
  101.           CRobots will  most likely appeal to programmers (especially those
  102.        who  think  they  can  write  the  "best"  programs),  computer game
  103.        enthusiasts,  people  wishing to learn the C language, and those who
  104.        are   interested   in   compiler   design   and   virtual   computer
  105.        interpreters.  
  106.  
  107.  
  108.        _2_-_3_.  _M_a_c_h_i_n_e _a_n_d _s_o_f_t_w_a_r_e _r_e_q_u_i_r_e_m_e_n_t_s 
  109.  
  110.                - Amiga 500, 1000, 2000, 2500
  111.                - 1 meg of RAM
  112.                - DOS 1.3 or higher
  113.                - ARP 1.3 or higher
  114.                - Monochrome or Color monitor
  115.                - Text editor (Ed, or your own favorite)
  116.  
  117.  
  118.  
  119.  
  120.                                   Page 1
  121.  
  122.  
  123. Tom Poindexter '85                                      David Wright '89-90
  124.  
  125.  
  126.           NOTE: I  have  not  tried  running  CRobots  on  a  512k  system.
  127.        However,  due  to  the  size  of the program I am assuming it should
  128.        work  if  you  juggle  the  stack size around and don't load up more
  129.        than  2  robots.  I usually run with a stack size of 50k, but I have
  130.        tested  CRobots with a stack of 40k and had no ill effects. It might
  131.        be  possible  to run it with a stack as small as 4k, but I can't say
  132.        for sure.  
  133.  
  134.        _2_-_4_.  _U_s_e_r _i_n_t_e_r_f_a_c_e 
  135.  
  136.           At the  present time CRobots does not use menus, windows, pop-ups
  137.        (other   than   a   file  requester),  or  any  other  user-friendly
  138.        interface.   Since  the  emphasis  is on designing and writing robot
  139.        control  programs, CRobots is usually started as a compiler is, from
  140.        the  AmigaDOS  command  line,  although  a  WorkBench  interface  is
  141.        available.  
  142.  
  143.  
  144.                                  _3_. _T_y_p_e_s _o_f _p_l_a_y
  145.  
  146.           CRobots can  either  run  one  match  (single play), in which the
  147.        realtime  battlefield  simulator  is used, or several matches (match
  148.        play),  in  which  only the name of the winner is printed after each
  149.        match.  Single  play  is  the default. Match play is intended to see
  150.        how  robot  programs  perform on the average. Match play can consume
  151.        several  hours  of  computer time depending on the number of matches
  152.        and cpu cycle limit, and can be run overnight.  
  153.  
  154.  
  155.                                _4_.  _R_u_n_n_i_n_g _C_R_o_b_o_t_s
  156.  
  157.        _4_-_1_.  _C_o_m_m_a_n_d _l_i_n_e _o_p_t_i_o_n_s 
  158.  
  159.           CRobots can  be  started  from the CLI or a WorkBench icon. If it
  160.        is started from the CLI you may also specify several options.  
  161.  
  162.        Sample command line: 
  163.  
  164.          1>crobots [options] [robot-program-1 ... robot-program-n]
  165.  
  166.        Valid options are:
  167.  
  168.        TO file         Save the output from the compile listing ("COMPILE"
  169.                        option) or record matches ("MATCH" option) to <file>.
  170.  
  171.        COMPILE         Compile only, and produce virtual machine assembler
  172.                        code and symbol tables. You must have the source code
  173.                        (.r file) for a robot to use this function.
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.                                   Page 2
  181.  
  182.  
  183. Tom Poindexter '85                                      David Wright '89-90
  184.  
  185.  
  186.        DEBUG           Compile one program, and invoke machine level
  187.                        single step tracing. You must have the source code
  188.                        (.r file) for a robot to use this function.
  189.  
  190.        MATCH xxx       Run a series of matches, where "xxx" is the number
  191.                        of matches. If "MATCH" is not specified, then the
  192.                        default is to run one match and display the
  193.                        battlefield in realtime. If the MATCH option is
  194.                        selected, all the robots must be pre-compiled.
  195.  
  196.        LIMIT xxx       Limit the number of machine cpu cycles per match
  197.                        when "MATCH" is specified. The default cycle limit
  198.                        is 500,000 when "MATCH" is specified
  199.  
  200.        NOSHOW          Turn off compilation display to increase speed.
  201.  
  202.  
  203.        robot-programs  The file name of the CRobots source program(s).
  204.                        (Wildcards allowed) Up to four files may be
  205.                        specified. If only one file is specified, it will
  206.                        be "cloned" into another, so that two robots
  207.                        (running the same program) will compete. Any file
  208.                        name may be used, but for consistency please use
  209.                        '.r' as an extension for source code. If you do
  210.                        not give any robot file names, all the names you
  211.                        give can't be found, or you run CRobots from the
  212.                        WorkBench, the ARP file requester will come up
  213.                        and allow you to select up to 4 robots.
  214.                        If you do not wish to load 4 robots, just click
  215.                        the CANCEL gadget after selecting the last robot
  216.                        you want to load.
  217.  
  218.           Note that  some of these options are mutually-exclusive, and that
  219.        others will have no effect depending on the mode you are in.  
  220.  
  221.        _4_-_2_.  _E_x_a_m_p_l_e_s_:
  222.  
  223.                1) Watch three robots compete with full display:
  224.                     1>crobots robot1.cr robot2.cr robot3.cr
  225.  
  226.                2) Compile one robot, and save the listing:
  227.                     1>crobots COMPILE TO robot1.lst robot1.r
  228.  
  229.                3) Debug a robot (first get an assembler code listing,
  230.                   as in example 2:
  231.                     1>crobots DEBUG robot1.r
  232.  
  233.                4) Run 50 matches, limiting total cpu cycles to 200,000
  234.                   (per match), and save results:
  235.                     1>crobots MATCH 50 LIMIT 200000 TO save rbt1.cr rbt2.cr
  236.  
  237.                5) Display command line options
  238.  
  239.  
  240.                                   Page 3
  241.  
  242.  
  243. Tom Poindexter '85                                      David Wright '89-90
  244.  
  245.  
  246.                     1>crobots ?<return>?<return>
  247.  
  248.  
  249.        _4_-_3_. _R_u_n_n_i_n_g _C_R_o_b_o_t_s _f_r_o_m _t_h_e _W_o_r_k_B_e_n_c_h 
  250.  
  251.           If you  wish you may start CRobots from the WorkBench by clicking
  252.        on  it's  icon.  You  may also specify some of the options that were
  253.        available  from  the CLI by using the icon's "tool types" array. You
  254.        can  edit  this  array by clicking on the CRobots icon _o_n_c_e and then
  255.        selecting  the  menu  option  "Info". You will see a blank line that
  256.        has  ADD  and  DEL  gadgets to the right of it. Click the ADD gadget
  257.        and  a  cursor  will  appear at the start of the blank line. Type in
  258.        one  of  the  following keywords followed by an equals sign, and the
  259.        value  you  want  (value  limits are the same as for the CLI options
  260.        above): 
  261.  
  262.                   MATCHES 
  263.                   LIMIT 
  264.                   NOSHOW 
  265.  
  266.           Matches and  limit  take  numeric  arguments,  as  under the CLI,
  267.        while  the  noshow option should be followed by a YES if you wish to
  268.        turn the option on (see above for what the noshow flag does).  
  269.           You may  add  as  many of these options as you wish, but you must
  270.        use  the ADD gadget to create each new option, and the DEL gadget to
  271.        delete options that you no longer want.  
  272.           Once you  have added/deleted the options that you want, click the
  273.        SAVE gadget to exit and save them to disk.  
  274.  
  275.        _4_-_4_. _W_o_r_k_b_e_n_c_h _e_x_a_m_p_l_e_s 
  276.  
  277.                   1) Set the number of matches to 3, with a limit of 
  278.                      20,000 cycles per match: 
  279.                           MATCHES=3 
  280.                           LIMIT=20000 
  281.  
  282.                   2) Turn off screen output of robot compilations: 
  283.                           NOSHOW=YES 
  284.  
  285.  
  286.                                _5_.  _G_a_m_e _p_a_r_a_m_e_t_e_r_s
  287.  
  288.        _5_-_1_.  _B_a_t_t_l_e_f_i_e_l_d 
  289.  
  290.           The battlefield  is  a  1,000  by  1,000  meter  square.  A  wall
  291.        surrounds  the perimeter, so that a robot running into the wall will
  292.        incur  damage. Note that as screen resolution is obviously less than
  293.        1000x1000,  there  is  bound  to be some error is scaling which will
  294.        make  robots  appear  to  be hit by pulses when they take no damage.
  295.        Robots  may  also appear to go over each other, and take damage from
  296.        hitting  walls  when  they  appear to be a slight distance away from
  297.        them.  
  298.  
  299.  
  300.                                   Page 4
  301.  
  302.  
  303. Tom Poindexter '85                                      David Wright '89-90
  304.  
  305.  
  306.  
  307.           The lower  left  corner  has  the  coordinates  x = 0, y = 0; the
  308.        upper  right  corner has the coordinated x = 999, y = 999. There are
  309.        grids  on  the  floor of the battlefield, and emitter/detector pairs
  310.        on  the  bottom  of  the  robot which allow it to keep track of it's
  311.        position much like an optical mouse.  
  312.  
  313.           The compass  system  is  oriented  so  that due east (right) is 0
  314.        degrees,  90  is  north, 180 is west, 270 is south. One degree below
  315.        due east is 359.  
  316.  
  317.  
  318.                         135    90   45
  319.                             \  |  / 
  320.                              \ | /
  321.                        180 --- x --- 0
  322.                              / | \
  323.                             /  |  \ 
  324.                         225   270   315
  325.  
  326.  
  327.        _5_-_2_.  _R_o_b_o_t _o_f_f_e_n_s_e
  328.  
  329.           The main  offensive  weapons are the phased particle cannon (PPC)
  330.        and  scanner.  The  PPC  has  a  range of 700 meters. The PPC may be
  331.        fired  an  unlimited  number  of  times,  but  a  recharging  factor
  332.        effectively  limits  the number of pulses in the air at any one time
  333.        to  two.  The PPC is mounted on an independent turret, and therefore
  334.        can fire any direction, 0-359, regardless of robot heading.  
  335.  
  336.           The scanner  is  an  optical  device  that can instantly scan any
  337.        chosen  heading,  0-359. The scanner has a maximum resolution of +/-
  338.        10  degrees.   This enables the robot to quickly scan the field at a
  339.        low   resolution,   then  use  maximum  resolution  to  pinpoint  an
  340.        opponent.  
  341.  
  342.  
  343.        _5_-_3_.  _R_o_b_o_t _d_e_f_e_n_s_e 
  344.  
  345.           The only  defenses  available  are  the  motor  drive  and status
  346.        registers.  The  motor  can  be  engaged  on  any heading, 0-359, in
  347.        speeds  from  0-100 percent of power. Robot mass is considerable, so
  348.        there  are acceleration and deacceleration delay factors. A speed of
  349.        0  stops  the  motor.  Turns  can be negotiated at speeds of 50% and
  350.        less,  in  any  direction. Of course, the motor drive can be engaged
  351.        any  time,  and  is necessary on offense when a target is beyond the
  352.        700 meter range of the PPC.  
  353.  
  354.           There are   several  embedded  controllers  in  the  robot  which
  355.        utilize  a  shared memory system (18 DMA channels) to update certain
  356.        status  registers  without  tying  up  the  primary  robot  CPU. The
  357.        primary  registers indicate the percent of damage, and current x and
  358.  
  359.  
  360.                                   Page 5
  361.  
  362.  
  363. Tom Poindexter '85                                      David Wright '89-90
  364.  
  365.  
  366.        y  locations  on  the battlefield. Another register provides current
  367.        drive speed.  
  368.  
  369.  
  370.        _5_-_4_.  _D_i_s_a_b_l_i_n_g _o_p_p_o_n_e_n_t_s 
  371.  
  372.           A robot  is considered dead when the damage reaches 100%. Percent
  373.        of damage inflicted is as follows: 
  374.  
  375.                2% - collision into another robot (both robots in a
  376.                     collision receive damage) or into a wall. A
  377.                     collision also causes the motor drive to disengage,
  378.                     and speed is reduced to 0.
  379.  
  380.                3% - a pulse impacting within a 40 meter radius.
  381.  
  382.                5% - a pulse impacting within a 20 meter radius.
  383.  
  384.               10% - a pulse impacting within a 5 meter radius.
  385.  
  386.  
  387.           Damage is  cumulative,  and  cannot be repaired. However, a robot
  388.        does  not  lose  any mobility, firing potential, etc. at high damage
  389.        levels.  In other words, a robot at 99% damage performs just as well
  390.        as a robot with no damage.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.                                   Page 6
  421.  
  422.  
  423. Tom Poindexter '85                                      David Wright '89-90
  424.  
  425.  
  426.        _5_-_5_.  _S_a_m_p_l_e _d_i_s_p_l_a_y
  427.  
  428.  
  429.                                                          (Status
  430.                                        (x=999,y=999)        blocks)
  431.  
  432.           +------------------------------------+ 1 fubar.r
  433.           |                                    |  D% 015   Sc 218
  434.           |                          \|/ 1     |  Sp 000   Hd 090
  435.           |       (pulse impacting)  -#-       | ------------------
  436.           |                          /|\       | 2 snafu.r
  437.        (y |                                    |  D% 050   Sc 275
  438.           |              + -------(particle    |  Sp 100   Hd 180
  439.        a  |                     + --pulses)    | ------------------
  440.        x  |   2                                | 3 bimbo.r
  441.        i  |                                    |  D% 000   Sc 045
  442.        s) |                 3                  |  Sp 000   Hd 000
  443.           |                /                   | ------------------
  444.           |          (robots) ----\            | 4 kumquat.r
  445.           |                         4          |  D% 100   Sc 050
  446.           |                                    |  Sp 000   Hd 335
  447.           |                                    | 
  448.           |                                    |
  449.           +------------------------------------+ CPU Cycle: 4500
  450.  
  451.        (x=0,y=0)         (x axis)
  452.  
  453.           The CRobots  battle  console  consists of several color CRT's and
  454.        an  LCD  counter. The largest CRT is the primary battle display, and
  455.        displays  the  battle  in  real-time.  The  smaller CRT's are status
  456.        blocks for each robot.  
  457.  
  458.           Each status  block  shows  the file name of the robot, the damage
  459.        incurred  (D%),  the  current  scan degrees(Sc), the speed (Sp), and
  460.        heading  (Hd).  Robots  are  represented  on  the field by a graphic
  461.        item,  which is also displayed to the left of the name in the status
  462.        block  for  reference.  If Damage is below 90%, it will be displayed
  463.        in  green.  If  damage  is between 90 & 100% it will be displayed in
  464.        red.  When  damage  reaches  100%  and  the robot is dead it will be
  465.        displayed in black.  
  466.  
  467.           The number  of  elapsed  robot  cpu  cycles  is  shown  in an LCD
  468.        display below the status blocks.  
  469.  
  470.           The CRobots  program  can  be aborted at any time by pressing the
  471.        ESC  key. It may also be paused at almost any time by pressing SPACE
  472.        or CTRL-S, and restarted by pressing SPACE again or CTRL-Q.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.                                   Page 7
  481.  
  482.  
  483. Tom Poindexter '85                                      David Wright '89-90
  484.  
  485.  
  486.                                  _6_.  _C_R_o_b_o_t_s _C_P_U
  487.  
  488.           The robot  cpu  is  a simple stack-oriented computer. It operates
  489.        at  very  slow  speeds  (on  a  7.8  MHz 68000 Amiga with an average
  490.        amount  of  background tasks running and with two robots loaded, the
  491.        average  speed  is 309 instructions per second, .000309 mips!!). The
  492.        word  size  is  32 bits, allowing integer values from -2,147,483,648
  493.        to  2,147,483,647.  There are internal pointer registers that manage
  494.        stack  usage,  but are not accessible from a robot program. The same
  495.        is true for an implicit accumulator.  
  496.  
  497.            The maximum  code  space is 1,000 instructions. All instructions
  498.        are  equal  in length. The maximum stack size is 500 words, which is
  499.        used  for data and function call/returns. The stack grows upward for
  500.        data  usage,  and downward (from the end) for function call/returns.
  501.        Three  words  are used for each function call, and are released upon
  502.        the  function  return.  The data portion and call/return portion are
  503.        managed by separate internal stack pointers.  
  504.  
  505.           If the  data stack pointer and call/return stack pointer collide,
  506.        a  stack  overflow  occurs.  In this case, the robot is restarted at
  507.        the 'main' function, with the stack reset to all zeros.  
  508.  
  509.           For more  information,  see  the  section on machine instructions
  510.        and theory.  
  511.  
  512.  
  513.                               _7_.  _C_R_o_b_o_t_s _C _c_o_m_p_i_l_e_r
  514.  
  515.        _7_-_1_.  _D_e_s_c_r_i_p_t_i_o_n 
  516.  
  517.           The CRobots   compiler   accepts   a  limited  subset  of  the  C
  518.        language.   There  is  no  provision for separate compilation, i.e.,
  519.        all  modules  of  a  program must be in one file. No preprocessor is
  520.        provided   for   "#define",   "#include",   etc.   Identifiers   are
  521.        significant  to  7  characters, although any length may be used. The
  522.        compiler  will  compile  any  file,  but  will  convert any existing
  523.        extension  to  (or  add  the  extension) ".cr". CRobots reserves the
  524.        extension  ".cr" for "Compiled Robot", and will not like other files
  525.        using  the  same  names. For consistency, use the extension ".r" for
  526.        robot  source  code  files,  and  let  the  compiler convert them to
  527.        ".cr".  
  528.  
  529.        _7_-_2_.  _F_e_a_t_u_r_e_s _m_i_s_s_i_n_g _f_r_o_m _s_t_a_n_d_a_r_d _C 
  530.  
  531.           Major language  features  missing  from  K&R are:  floating point
  532.        variables,   structures,  unions,  pointers,  initializers,  arrays,
  533.        character   data,  typedefs,  for  statement,  do..while  statement,
  534.        switch..case  statement,  break, continue, gotos and labels, ternary
  535.        and  comma operators, octal and hexadecimal constants, no parameters
  536.        to main(), and all preprocessor directives.  
  537.  
  538.  
  539.  
  540.                                   Page 8
  541.  
  542.  
  543. Tom Poindexter '85                                      David Wright '89-90
  544.  
  545.  
  546.  
  547.        _7_-_3_.  _C_R_o_b_o_t_s _l_a_n_g_u_a_g_e 
  548.  
  549.           The language  features that are present are entirely suitable for
  550.        writing  robot  control  programs.  Basic  programming constructs of
  551.        if..then..else,  while, and function calls can be used freely.  Full
  552.        expression evaluation is also provided, so that statements such as: 
  553.  
  554.                if ((x = func1(y,1,++z,func2(c))) > 0) 
  555.                  a = 0; 
  556.                else 
  557.                  a = x; 
  558.  
  559.        are  perfectly legal. Ifs and whiles may be nested, and recursion is
  560.        supported.  Variables  declared  outside  a  function definition are
  561.        global  in  scope,  whereas  variables  declared  inside  a function
  562.        definition are local to that function.  
  563.  
  564.  
  565.        The following keywords are recognized: 
  566.  
  567.        ccoommmmeennttss::
  568.        "/* ... */"     comments
  569.        _c_a_n_n_o_t
  570.        be nested
  571.  
  572.        ccoonnssttaannttss::
  573.        any decimal digits, optionally preceeded with a '-'
  574.  
  575.        ddeeccllaarraattiioonnss::
  576.        "int"           variable declare
  577.        "long"          same as int
  578.        "auto"          default storage scope, optional
  579.        "register"      legal, but ignored, same as auto
  580.        "function (parms,.....)"  function definition
  581.  
  582.        llooggiicc ccoonnttrrooll::
  583.        "if (expr) STMT else STMT"
  584.  
  585.        iitteerraattiioonn::
  586.        "while (expr) STMT"
  587.  
  588.        ffuunnccttiioonn rreettuurrnn::
  589.        "return"        return
  590.        "return expr"   return with a value
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.                                   Page 9
  601.  
  602.  
  603. Tom Poindexter '85                                      David Wright '89-90
  604.  
  605.  
  606.        aassssiiggnnmmeenntt ooppeerraattoorrss::
  607.        "="             assignment
  608.        ">>="           assignment shift right
  609.        "<<="           assignment shift left
  610.        "+="            assignment addition
  611.        "-="            assignment subtraction
  612.        "*="            assignment multiplication
  613.        "/="            assignment division
  614.        "%="            assignment modulo
  615.        "&="            assignment and
  616.        "^="            assignment exclusive or
  617.        "|="            assignment inclusive or
  618.  
  619.        bbiitt--wwiissee ooppeerraattoorrss::
  620.        ">>"            shift right
  621.        "<<"            shift left
  622.        "&"             and
  623.        "!"             unary not
  624.        "~"             unary one's complement
  625.        "^"             exclusive or
  626.        "|"             inclusive or
  627.  
  628.        iinnccrreemmeenntt//ddeeccrreemmeenntt ooppeerraattoorrss::
  629.        "++"            prefix increment, see derivations
  630.        "--"            prefix decrement, see derivations
  631.  
  632.        llooggiiccaall ooppeerraattoorrss::
  633.        "&&"            logical and
  634.        "||"            logical or
  635.        "<="            logical less than or equal
  636.        ">="            logical greater than or equal
  637.        "=="            logical equal
  638.        "!="            logical not equal
  639.        "<"             logical less than
  640.        ">"             logical greater than
  641.  
  642.        aarriitthhmmeettiicc ooppeerraattoorrss::
  643.        "-"             subtraction or unary negation
  644.        "+"             addition
  645.        "*"             multiplication
  646.        "/"             division
  647.        "%"             modulo
  648.  
  649.        mmiisscc::
  650.        ";"             statement terminator or null statement
  651.        "{ }"           compound statement
  652.        ","             parameter separator in function definition or call
  653.        "( )"           expression or function definition or call
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.                                   Page 10
  661.  
  662.  
  663. Tom Poindexter '85                                      David Wright '89-90
  664.  
  665.  
  666.        Precedence and order of evaluation are the same as in K&R.
  667.  
  668.                Operator                Associativity
  669.                ()                      left to right
  670.                ! ~ ++ -- -             right to left
  671.                * / %                   left to right
  672.                + -                      "   "    "
  673.                << >>                    "   "    "
  674.                < <= => >                "   "    "
  675.                == !=                    "   "    "
  676.                &                        "   "    "
  677.                ^                        "   "    "
  678.                |                        "   "    "
  679.                &&                       "   "    "
  680.                ||                       "   "    "
  681.                = -= += etc.            right to left
  682.  
  683.  
  684.        Major derivations from K&R:
  685.  
  686.       -Local variables  need  not  be  declared before reference, i.e., any
  687.        undeclared variable will default to a local variable.  
  688.  
  689.       -Postfix increment   and   decrement   ("var++"   or   "var--")   are
  690.        recognized,    but    the    result    is   the   same   as   prefix
  691.        increment/decrement ("++var").  
  692.  
  693.       -Intrinsic function names are reserved.  
  694.  
  695.  
  696.        _7_-_4_.  _C_o_m_p_i_l_e_r _l_i_m_i_t_s 
  697.  
  698.            defined functions:             64 
  699.            local variables per function:  64 
  700.            external variables:            64 
  701.            if nest level:                 16 
  702.            while nest level:              16 
  703.            line length                    2000 bytes 
  704.  
  705.  
  706.        _7_-_5_.  _C_o_m_p_l_i_e_r _e_r_r_o_r _a_n_d _w_a_r_n_i_n_g _m_e_s_s_a_g_e_s_: 
  707.  
  708.           The compiler  has  no  error  recovery and will stop on the first
  709.        error found. Warning messages do not stop the compiler.  
  710.  
  711.        EErrrroorr mmeessssaaggeess 
  712.  
  713.        "syntax error"  -  Any  input that results in improper C syntax will
  714.             yield  "syntax  error",  with  an  indicator  pointing  to  the
  715.             unrecognizable input.  
  716.  
  717.  
  718.  
  719.  
  720.                                   Page 11
  721.  
  722.  
  723. Tom Poindexter '85                                      David Wright '89-90
  724.  
  725.  
  726.        "instruction space  exceeded" - compiler tried to generate more than
  727.             1000 machine instructions.  
  728.  
  729.        "symbol pool  exceeded"  -  the  maximum  local  variable,  external
  730.             variable, or function definition symbol table was exceeded.  
  731.  
  732.        "function referenced  but  not  found"  -  a function was referenced
  733.             that  was  not defined in the input file or is not an intrinsic
  734.             function.  
  735.  
  736.        "main not  defined"  -  the  input  file  did  not define a 'main()'
  737.             function.  
  738.  
  739.        "function definition  same  as  intrinsic"  - a function was defined
  740.             with   the  same  name  as  an  intrinsic  function,  which  is
  741.             reserved.  
  742.  
  743.        "if nest level exceeded" - more than 16 'if's were nested.  
  744.  
  745.        "while nest level exceeded" - more than 16 'while's were nested.  
  746.  
  747.        "yacc stack  overflow"  - the compiler's parser overflowed, probably
  748.             due to complex expressions and/or extreme nesting.  
  749.  
  750.        WWaarrnniinngg mmeessssaaggeess 
  751.  
  752.           These messages  will  not  cause  the  compiler  to fail, but may
  753.        cause the program to execute unexpectedly.  
  754.  
  755.        "unsupported initializer"  -  variable  declares  cannot  include an
  756.             initializer. For future releases.  
  757.  
  758.        "unsupported break"  -  the 'break' statement was found and ignored.
  759.             For future releases.  
  760.  
  761.        "n postfix  operators"  -  postfix  increment or decrement operators
  762.             were used, and are coerced into prefix expressions.  
  763.  
  764.        "n undeclared  variables"  -  one  or more variables were implicitly
  765.             declared.  
  766.  
  767.        "code utilization:   n%"   -   reports   the   capacity  of  machine
  768.             instructions generated.  
  769.  
  770.                      _8_.  _C_R_o_b_o_t_s _C _I_n_t_r_i_n_s_i_c _F_u_n_c_t_i_o_n _L_i_b_r_a_r_y
  771.  
  772.           The intrinsic  function  library  provides  machine level control
  773.        and  certain  arithmetic  functions.  These functions do not consume
  774.        any  of  the  program code space or data stack, except for the three
  775.        words  for call/return sequences. No explicit linking is required to
  776.        use any intrinsic function.  
  777.  
  778.  
  779.  
  780.                                   Page 12
  781.  
  782.  
  783. Tom Poindexter '85                                      David Wright '89-90
  784.  
  785.  
  786.  
  787.        scan (degree,resolution) 
  788.  
  789.           The scan()  function  invokes the robot's scanner, at a specified
  790.        degree  and resolution. scan() returns 0 if no robots are within the
  791.        scan  range  or  a  positive  integer  representing the range to the
  792.        closest  robot.  Degree  should be within the range 0-359, otherwise
  793.        degree  is  forced  into  0-359  by a modulo 360 operation, and made
  794.        positive  if  necessary.  Resolution  controls the scanner's sensing
  795.        resolution, up to +/- 10 degrees.  Examples: 
  796.           range = scan(45,0); /* scan 45, with no variance */ 
  797.           range = scan(365,10); /* scans the range from 355 to 15 */ 
  798.  
  799.  
  800.        cannon (degree,range) 
  801.  
  802.           The cannon()  function  fires  the  PPC  at a specified range and
  803.        direction.  cannon()  returns 1 (true) if a pulse was discharged, or
  804.        0  (false) if the PPC is recharging. Degree is forced into the range
  805.        0-359  as  in  scan().  Range  can  be  0-700,  with  greater ranges
  806.        truncated to 700.  Examples: 
  807.           degree = 45;    /* set a direction to test */ 
  808.           if ((range=scan(degree,2)) > 0) /* see if a target is there */ 
  809.             cannon(degree,range);  /* fire a missile */ 
  810.  
  811.  
  812.        drive (degree,speed) 
  813.  
  814.           The drive()  function activates the robot's drive mechanism, on a
  815.        specified  heading  and speed. Degree is forced into the range 0-359
  816.        as  in scan(). Speed is expressed as a percent, with 100 as maximum.
  817.        A  speed  of  0  disengages  the  drive. Changes in direction can be
  818.        negotiated at speeds of less than 50 percent.  Examples: 
  819.           drive(0,100);  /* head due east, at maximum speed */ 
  820.           drive(90,0);   /* stop motion */ 
  821.  
  822.  
  823.        damage() 
  824.  
  825.           The damage()  function  returns  the  current  amount  of  damage
  826.        incurred.  damage()  takes  no arguments, and returns the percent of
  827.        damage,  0-99.  (100  percent  damage  means the robot is completely
  828.        disabled, thus no longer running!) Examples: 
  829.          d = damage();       /* save current state */ 
  830.          ; ; ;               /* other instructions */ 
  831.          if (d != damage())  /* compare current state to prior state */ 
  832.          { 
  833.            drive(90,100);    /* robot has been hit, start moving */ 
  834.            d = damage();     /* get current damage again */ 
  835.          } 
  836.  
  837.  
  838.  
  839.  
  840.                                   Page 13
  841.  
  842.  
  843. Tom Poindexter '85                                      David Wright '89-90
  844.  
  845.  
  846.        speed () 
  847.  
  848.           The speed()  function  returns  the  current  speed of the robot.
  849.        speed()  takes  no  arguments,  and  returns  the  percent of speed,
  850.        0-100.  Note  that  speed()  may  not always be the same as the last
  851.        drive(),   because   of   acceleration  and  deacceleration  delays.
  852.        Examples: 
  853.          drive(270,100);   /* start drive, due south */ 
  854.          ; ; ;             /* other instructions */ 
  855.          if (speed() == 0) /* check current speed */ 
  856.          { 
  857.            drive(90,20); /* ran into the south wall, or another robot*/ 
  858.          } 
  859.  
  860.  
  861.  
  862.        loc_x ()     loc_y () 
  863.  
  864.           The loc_x()   function   returns   the  robot's  current  x  axis
  865.        location.   loc_x()  takes  no  arguments,  and  returns 0-999.  The
  866.        loc_y()  function  is  similar to loc_x(), but returns the current y
  867.        axis position.  
  868.           Examples: 
  869.              drive (180,50);  /* start heading for west wall */ 
  870.              while (loc_x() > 20) 
  871.                ;              /* do nothing until we are close */ 
  872.              drive (180,0);   /* stop drive */ 
  873.  
  874.  
  875.        rand (limit) 
  876.  
  877.           The rand()  function returns a random number between 0 and limit,
  878.        up to 32767.  
  879.           Examples: 
  880.             degree = rand(360);     /* pick a random starting point */ 
  881.             range = scan(degree,0); /* and scan */ 
  882.  
  883.  
  884.        sqrt (number) 
  885.  
  886.           The sqrt()  returns  the  square root of a number. Number is made
  887.        positive, if necessary.  
  888.           Examples: 
  889.              x = x1 - x2;     /* compute the classical distance formula */ 
  890.              y = y1 - y2;     /* between two points (x1,y1) (x2,y2) */ 
  891.              distance = sqrt((x*x) - (y*y));  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.                                   Page 14
  901.  
  902.  
  903. Tom Poindexter '85                                      David Wright '89-90
  904.  
  905.  
  906.        sin (degree)    cos (degree)     tan (degree)     atan (ratio) 
  907.  
  908.           These functions  provide  trigonometric values. sin(), cos(), and
  909.        tan(),  take a degree argument, 0-359, and returns the trigonometric
  910.        value  times  100,000. The scaling is necessary since the CROBOT cpu
  911.        is  an  integer  only  machine,  and trig values are between 0.0 and
  912.        1.0.  atan()  takes  a  ratio  argument  that  has been scaled up by
  913.        100,000,  and  returns  a  degree  value,  between  -90 and +90. The
  914.        resulting  calculation  should  not  be  scaled  to the actual value
  915.        until   the   final   operation,  as  not  to  lose  accuracy.   See
  916.        programming examples for usage.  
  917.  
  918.  
  919.                          _9_.  _C_R_o_b_o_t_s _C _P_r_o_g_r_a_m _S_t_r_u_c_t_u_r_e
  920.  
  921.        _9_-_1_.  _B_a_s_i_c _p_r_o_g_r_a_m _s_t_r_u_c_t_u_r_e 
  922.  
  923.           CRobots programs  are  not  unlike  other C programs. The minimum
  924.        CRobots  program  consist  of a function named "main". Additionally,
  925.        other functions can be defined, along with external variables.  
  926.           There is  one  restriction  about robot source files. The first 2
  927.        lines  are  reserved  for  the "Company" which produces a robot, and
  928.        the  "Author"  of the robot, respectively. As an example, a club may
  929.        use  the  same "company" name, while putting the programmer for each
  930.        robot  in  the  "author"  spot.  This lets you share your robot with
  931.        other  players,  and still get credit for writing it. Both "company"
  932.        and  "author"  may  be  up to 15 characters long. If you do not want
  933.        these fields, you _M_U_S_T make the first 2 lines blank.  
  934.  
  935.           When a  .r  file  is  compiled,  a file with the extension of .cr
  936.        will  be  created.  This  is  the  robot in a compiled and encrypted
  937.        format.  You  can  give  this file out for competition (as mentioned
  938.        above)  without  giving out your source code. Additionally, each .cr
  939.        file  keeps  track  of  wins  and  losses  since  the robot was last
  940.        compiled   (needless   to   say,  but  to  prevent  major  lawsuits,
  941.        recompiling a robot will clear out the stats).  
  942.  
  943.        _9_-_2 _"_s_n_i_p_e_r_._r_" 
  944.  
  945.           The following CRobots program is provided as an example.  
  946.  
  947.     CRobots, Inc.
  948.     T. Poindexter
  949.     /* sniper */
  950.     /* strategy: since a scan of the entire battlefield can be done in 90 */
  951.     /* degrees from a corner, sniper can scan the field quickly. */
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.                                   Page 15
  961.  
  962.  
  963. Tom Poindexter '85                                      David Wright '89-90
  964.  
  965.  
  966.     /* external variables, that can be used by any function */
  967.     int corner;           /* current corner 0, 1, 2, or 2 */
  968.     int c1x, c1y;         /* corner 1 x and y */
  969.     int c2x, c2y;         /*   "    2 "  "  " */
  970.     int c3x, c3y;         /*   "    3 "  "  " */
  971.     int c4x, c4y;         /*   "    4 "  "  " */
  972.     int s1, s2, s3, s4;   /* starting scan position for corner 1 - 4 */
  973.     int sc;               /* current scan start */
  974.     int d;                /* last damage check */
  975.  
  976.     /* main */
  977.     main()
  978.     {
  979.       int closest;        /* check for targets in range */
  980.       int range;          /* range to target */
  981.       int dir;            /* scan direction */
  982.  
  983.       /* initialize the corner info */
  984.       /* x and y location of a corner, and starting scan degree */
  985.       c1x = 10;  c1y = 10;  s1 = 0;
  986.       c2x = 10;  c2y = 990; s2 = 270;
  987.       c3x = 990; c3y = 990; s3 = 180;
  988.       c4x = 990; c4y = 10;  s4 = 90;
  989.       closest = 9999;
  990.       new_corner();       /* start at a random corner */
  991.       d = damage();       /* get current damage */
  992.       dir = sc;           /* starting scan direction */
  993.  
  994.       while (1) {         /* loop is executed forever */
  995.  
  996.         while (dir < sc + 90) {  /* scan through 90 degree range */
  997.           range = scan(dir,1);   /* look at a direction */
  998.           if (range <= 700 && range > 0) {
  999.             while (range > 0) {    /* keep firing while in range */
  1000.               closest = range;     /* set closest flag */
  1001.               cannon(dir,range);   /* fire! */
  1002.               range = scan(dir,1); /* check target again */
  1003.               if (d + 15 > damage())  /* sustained several hits, */
  1004.                 range = 0;            /* goto new corner */
  1005.             }
  1006.           dir -= 10;             /* back up scan, in case */
  1007.           }
  1008.  
  1009.           dir += 2;                /* increment scan */
  1010.           if (d != damage()) {     /* check for damage incurred */
  1011.             new_corner();          /* we're hit, move now */
  1012.             d = damage();
  1013.             dir = sc;
  1014.           }
  1015.         }
  1016.  
  1017.  
  1018.  
  1019.  
  1020.                                   Page 16
  1021.  
  1022.  
  1023. Tom Poindexter '85                                      David Wright '89-90
  1024.  
  1025.  
  1026.         if (closest == 9999) {       /* check for any targets in range */
  1027.           new_corner();             /* nothing, move to new corner */
  1028.           d = damage();
  1029.           dir = sc;
  1030.         } else                      /* targets in range, resume */
  1031.           dir = sc;
  1032.         closest = 9999;
  1033.       }
  1034.  
  1035.     }  /* end of main */
  1036.  
  1037.     /* new corner function to move to a different corner */
  1038.     new_corner() {
  1039.       int x, y;
  1040.       int angle;
  1041.       int new;
  1042.  
  1043.       new = rand(4);           /* pick a random corner */
  1044.       if (new == corner)       /* but make it different than the */
  1045.         corner = (new + 1) % 4;/* current corner */
  1046.       else
  1047.         corner = new;
  1048.       if (corner == 0) {       /* set new x,y and scan start */
  1049.         x = c1x;
  1050.         y = c1y;
  1051.         sc = s1;
  1052.       }
  1053.       if (corner == 1) {
  1054.         x = c2x;
  1055.         y = c2y;
  1056.         sc = s2;
  1057.       }
  1058.       if (corner == 2) {
  1059.         x = c3x;
  1060.         y = c3y;
  1061.         sc = s3;
  1062.       }
  1063.       if (corner == 3) {
  1064.         x = c4x;
  1065.         y = c4y;
  1066.         sc = s4;
  1067.       }
  1068.  
  1069.       /* find the heading we need to get to the desired corner */
  1070.       angle = plot_course(x,y);
  1071.  
  1072.       /* start drive train, full speed */
  1073.       drive(angle,100);
  1074.  
  1075.       /* keep traveling until we are within 100 meters */
  1076.       /* speed is checked in case we run into wall, other robot */
  1077.       /* not terribly great, since were are doing nothing while moving */
  1078.  
  1079.  
  1080.                                   Page 17
  1081.  
  1082.  
  1083. Tom Poindexter '85                                      David Wright '89-90
  1084.  
  1085.  
  1086.  
  1087.       while (distance(loc_x(),loc_y(),x,y) > 100 && speed() > 0)
  1088.         ;
  1089.  
  1090.       /* cut speed, and creep the rest of the way */
  1091.  
  1092.       drive(angle,20);
  1093.       while (distance(loc_x(),loc_y(),x,y) > 10 && speed() > 0)
  1094.         ;
  1095.  
  1096.       /* stop drive, should coast in the rest of the way */
  1097.       drive(angle,0);
  1098.     }  /* end of new_corner */
  1099.  
  1100.     /* classical pythagorean distance formula */
  1101.     distance(x1,y1,x2,y2)
  1102.     int x1;
  1103.     int y1;
  1104.     int x2;
  1105.     int y2;
  1106.     {
  1107.       int x, y;
  1108.  
  1109.       x = x1 - x2;
  1110.       y = y1 - y2;
  1111.       d = sqrt((x*x) + (y*y));
  1112.       return(d);
  1113.     }
  1114.  
  1115.     /* plot course function, return degree heading to */
  1116.     /* reach destination x, y; uses atan() trig function */
  1117.     plot_course(xx,yy)
  1118.     int xx, yy;
  1119.     {
  1120.       int d;
  1121.       int x,y;
  1122.       int scale;
  1123.       int curx, cury;
  1124.  
  1125.       scale = 100000;  /* scale for trig functions */
  1126.       curx = loc_x();  /* get current location */
  1127.       cury = loc_y();
  1128.       x = curx - xx;
  1129.       y = cury - yy;
  1130.  
  1131.       /* atan only returns -90 to +90, so figure out how to use */
  1132.       /* the atan() value */
  1133.  
  1134.       if (x == 0) {      /* x is zero, we either move due north or south */
  1135.         if (yy > cury)
  1136.           d = 90;        /* north */
  1137.         else
  1138.  
  1139.  
  1140.                                   Page 18
  1141.  
  1142.  
  1143. Tom Poindexter '85                                      David Wright '89-90
  1144.  
  1145.  
  1146.           d = 270;       /* south */
  1147.       } else {
  1148.         if (yy < cury) {
  1149.           if (xx > curx)
  1150.             d = 360 + atan((scale * y) / x);  /* south-east, quadrant 4 */
  1151.           else
  1152.             d = 180 + atan((scale * y) / x);  /* south-west, quadrant 3 */
  1153.         } else {
  1154.           if (xx > curx)
  1155.             d = atan((scale * y) / x);        /* north-east, quadrant 1 */
  1156.           else
  1157.             d = 180 + atan((scale * y) / x);  /* north-west, quadrant 2 */
  1158.         }
  1159.       }
  1160.       return (d);
  1161.     }
  1162.  
  1163.  
  1164.           Notes:  The  distance()  and  plot_course()  routines  are  quite
  1165.        handy.  Save  them  for your programs. Also, note that the main scan
  1166.        routine  will  "back up" a few degrees after a target has been found
  1167.        and  fired  upon.  This should catch robots trying to flee away from
  1168.        the  direction  you are scanning. If the target moves the other way,
  1169.        the normal scan increment will find it.  
  1170.  
  1171.           See the other sample CRobots program files.  
  1172.  
  1173.  
  1174.                      _1_0_.  _C_R_o_b_o_t_s _C_P_U _A_r_c_h_i_t_e_c_t_u_r_e _a_n_d _T_h_e_o_r_y
  1175.  
  1176.           This information  is  provided  if  you  need  to  use  the debug
  1177.        facility,  or  are  curious  about  the virtual machine interpreter.
  1178.        Don't  bother reading this section if you are not so inclined; it is
  1179.        not needed for normal play.  
  1180.  
  1181.        _1_0_-_1_.  _S_t_a_c_k _u_s_a_g_e_: 
  1182.  
  1183.           The stack  is  controlled  implicitly  by several pointers. Stack
  1184.        pointers  are  not  accessible  through  machine  instructions. Most
  1185.        instructions  will  either push data onto the stack, or pop data off
  1186.        the  stack.  The  stack  is used from the bottom up (low memory) for
  1187.        data  and  temporary  storage,  and  is used from the top down (high
  1188.        memory)  for  saving  stack  pointers  and  the  program  counter on
  1189.        function call/return.  
  1190.  
  1191.           External (global)  variables  are allocated at the very bottom of
  1192.        the  stack,  and the local mark pointer for 'main' starts just after
  1193.        the  externals.  External variables are addressed from the beginning
  1194.        of the stack, by offset.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.                                   Page 19
  1201.  
  1202.  
  1203. Tom Poindexter '85                                      David Wright '89-90
  1204.  
  1205.  
  1206.           When a  function  is called (including 'main'), the stack pointer
  1207.        is  marked  (local  mark)  and  is  increased by the number of local
  1208.        variables  needed  for  that function. Local variables are addressed
  1209.        relative  to  the local mark, by offsets. All calculations, function
  1210.        calls,  and  constants  are  pushed  on  and popped off the stack as
  1211.        needed (temporary mark or top of stack).  
  1212.  
  1213.           A function  call  also  saves  its  current stack pointers (local
  1214.        variable  mark  and  frame  mark)  and  program counter. This return
  1215.        information grows from the top down.  
  1216.  
  1217.           Arguments are  passed  to  functions by value. The first argument
  1218.        in  a  function call becomes the first local variable for the called
  1219.        function. Consider the following: 
  1220.  
  1221.           main() {               /* main has three local variables: */ 
  1222.             int a, b, c; 
  1223.             ....; 
  1224.             sub1 (a,b/2,c+1);    /* call sub1, and pass arguments */ 
  1225.             ....; 
  1226.           } 
  1227.  
  1228.           sub1 (x,y,z)           /* sub1 takes three parameters and */ 
  1229.           int x, y, z; {         /* has one local variable */ 
  1230.             int result; 
  1231.             result = x + y + z; 
  1232.             return (result); 
  1233.           } 
  1234.  
  1235.           The main()  function  allocates  three  local  variables  on  the
  1236.        stack,  sets  its  local  mark  at 'a', and sets the temporary stack
  1237.        pointer  beyond  the locals. Just before sub1() is called, the value
  1238.        of  'a'  is pushed, followed by the result of 'b/2', and 'c+1'. When
  1239.        sub1()  is called, it sets its local mark where the value of 'a' is,
  1240.        so  that  'a'  is know as 'x' in func1(), likewise 'b/2' is known as
  1241.        'y'  and  'c+1' is known as 'z'. Sub1() also allocates one more word
  1242.        for  'result',  and  sets  the  temporary mark after the storage for
  1243.        'result'.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.                                   Page 20
  1261.  
  1262.  
  1263. Tom Poindexter '85                                      David Wright '89-90
  1264.  
  1265.  
  1266.           The following diagram illustrates the stack usage: 
  1267.  
  1268.                +------------+   <-- end of stack, high memory 
  1269.                |main return |   <-- return info for main 
  1270.                +------------+       (frame,ip,local mark) 
  1271.                |sub1 return |   <-- return info for sub1 
  1272.                +------------+       (etc.) 
  1273.                |     |      | 
  1274.                |     v      |   <-- additional function call return 
  1275.                |            |       info grow downwards 
  1276.                |            | 
  1277.                |            | 
  1278.                |            | 
  1279.                |     ^      |   <-- additional function calls and 
  1280.                |     |      |       expressions grow upwards 
  1281.                |expressions | 
  1282.                +------------+   <-- temporary mark (top of stack) 
  1283.                |sub1 locals | 
  1284.                +------------+   <-- local mark: sub1 function 
  1285.                |main locals | 
  1286.                +------------+   <-- local mark: main function 
  1287.                |            | 
  1288.                | Externals  | 
  1289.                |            | 
  1290.                +------------+   <-- beginning of stack 
  1291.  
  1292.  
  1293.        _1_0_-_2_.  _L_i_n_k _l_i_s_t 
  1294.  
  1295.           The link  list  is a list built by the compiler that contains the
  1296.        names  and link information of the functions within the program. The
  1297.        link  information  contains  the  starting  location of the function
  1298.        within  the  code, the number of parameters, and the number of other
  1299.        local  variables  within  the  function.  The  link  list  cannot be
  1300.        accessed by the user program.  
  1301.  
  1302.        _1_0_-_3_.  _I_n_s_t_r_u_c_t_i_o_n _s_e_t 
  1303.  
  1304.           The CRobots  cpu  has  10 instructions. Each instruction occupies
  1305.        the same amount of storage, with or without operands.  
  1306.  
  1307.        FETCH offset  (external  |  local) - Fetch will retrieve a word from
  1308.             either  the  external  variable pool or the local variable pool
  1309.             and  push  it  onto  the stack. The offset has its high-bit set
  1310.             (or'ed  with  0x8000)  if  it  is  an external (offset from the
  1311.             beginning  of  the stack), otherwise it is a local (offset from
  1312.             the local variable mark). See STORE.  
  1313.  
  1314.        STORE offset  (external  |  local),  opcode - Store pops the top two
  1315.             items,  applies  the  arithmetic  opcode  to  the two operands,
  1316.             pushes  the result on the top of the stack and stores it in the
  1317.             variable  referenced by the offset. Offsets are either external
  1318.  
  1319.  
  1320.                                   Page 21
  1321.  
  1322.  
  1323. Tom Poindexter '85                                      David Wright '89-90
  1324.  
  1325.  
  1326.             or  local,  according  to  the  method  described in Fetch. The
  1327.             result  of  the  opcode  is  left  on  the stack. See FETCH and
  1328.             BINOP.  
  1329.  
  1330.        CONST k - Const will push a constant onto the stack.  
  1331.  
  1332.        BINOP opcode  -  Binop  will pop the top two items as top of stack =
  1333.             y,  next  to  top of stack as x, apply the arithmetic opcode as
  1334.             (x  opcode  y),  and  push the result on the stack. Opcodes are
  1335.             decimal  representations  of  'C'  operators  such as '+', '/',
  1336.             '>=', etc. See STORE.  
  1337.  
  1338.        FCALL link-offset  -  Fcall  performs  a  high  level  function call
  1339.             facility.  The  link-offset  operand  specifies an entry in the
  1340.             link  list  table.  Fcall  pushes  its return information:  the
  1341.             next  instruction  counter and the current local variable mark.
  1342.             A  new  local  variable  mark  and temporary mark (top of stack
  1343.             pointer)   is   set.   The  cpu  then  branches  to  the  first
  1344.             instruction of the function. See RETSUB and FRAME.  
  1345.  
  1346.        RETSUB -  Retsub  returns  from a function, leaving the return value
  1347.             on  the  top  of  the stack. Retsub restores the previous local
  1348.             variable  pool,  the  next  instruction counter, and re-adjusts
  1349.             the  stack  frame  to  the  point  just  before the call. The C
  1350.             compiler  generates  code  to  return  a  dummy  value  if  the
  1351.             function does not explicitly return one. See FCALL and FRAME.  
  1352.  
  1353.        BRANCH instruction  -  Branch pops the top of the stack and branches
  1354.             to  the  instruction  if the value is zero. The next sequential
  1355.             instruction  is  executed  if  the value is anything other than
  1356.             zero.  
  1357.  
  1358.        CHOP -  Chop  discards  the  top  of  the  stack  by popping it into
  1359.             oblivion.  
  1360.  
  1361.        FRAME -  Frame facilitates fcall/retsub by saving the current top of
  1362.             stack  pointer  (temporary  mark)  in  anticipation  of a fcall
  1363.             statement.   The   top   of  stack  pointer  is  saved  in  the
  1364.             call/return stack as a frame marker. See FCALL and RETSUB.  
  1365.  
  1366.        NOP - No operation. Is used as a mark indicating the end of code.  
  1367.  
  1368.        _1_0_-_4_. _M_a_c_h_i_n_e _l_e_v_e_l _d_e_b_u_g_g_i_n_g 
  1369.  
  1370.           Debug mode   is   used   to  trace  by  single  stepping  machine
  1371.        instructions.  Use  this  only  if  you  need  to  see  your program
  1372.        execute, or are just curious.  
  1373.  
  1374.           First, get  a listing on paper of a compile with full information
  1375.        by using the 'COMPILE' option: 
  1376.                A>crobots COMPILE TO prt: yourpgm.r 
  1377.  
  1378.  
  1379.  
  1380.                                   Page 22
  1381.  
  1382.  
  1383. Tom Poindexter '85                                      David Wright '89-90
  1384.  
  1385.  
  1386.           Next, start CRobots again with the 'DEBUG' flag: 
  1387.                A>crobots DEBUG yourpgm.r 
  1388.  
  1389.           Your robot  will  be  placed  randomly in the field, and a target
  1390.        robot  will  be  placed  at the center of the field (x=500,y=500) so
  1391.        your robot program can find and shoot at a target.  
  1392.  
  1393.           The virtual  machine  interpreter  will  single step through your
  1394.        program  (machine  instructions,  that  is). At every instruction, a
  1395.        machine  instruction  is  disassembled, and the top of stack pointer
  1396.        and  value  are  printed.  The  top of stack and value are after the
  1397.        results  of  the instruction. Other information may also be printed,
  1398.        such as function calls searching the link list, etc.  
  1399.  
  1400.           On every  step, you are prompted "d,h,q,<cr>:". Entering 'd' will
  1401.        dump   external   and   local  variable  pools,  as  well  as  vital
  1402.        information  of  your  robot:   coordinates, heading, speed, damage,
  1403.        etc.,  and  the  status  of  any missiles your robot may have fired.
  1404.        Entering  'h'  will  simulate your robot taking a 10% damage hit, so
  1405.        you  can  check  damage  detection,  etc. Entering 'q' will quit the
  1406.        program  immediately,  and return you to AmigaDOS. A carriage return
  1407.        alone  will  continue  the stepping process. All responses ('d','h',
  1408.        or  'q')  should  be  in  lower  case  only. You should refer to the
  1409.        compile  listing  for  offsets  into the external and local variable
  1410.        pools, C code, etc.  
  1411.  
  1412.                             _1_1_.  _I_m_p_l_e_m_e_n_t_a_t_i_o_n _n_o_t_e_s
  1413.  
  1414.           CRobots is  written  entirely  in  'C'.  The compiler section was
  1415.        developed  with the aid of the Unix* (TM) programs 'yacc' and 'lex'.
  1416.        Yacc  (yet  another  compiler-compiler)  accepts  a 'grammar', which
  1417.        describes  the  CRobots  'C'  language. Yacc produces a 'C' function
  1418.        known  as  a  parser.  The  parser  is  the  heart  of the compiler,
  1419.        recognizing  valid  'C' constructs. Lex (lexical analyzer) accepts a
  1420.        list  of token combinations, and produces a 'C' function to scan the
  1421.        compiler   input   for   the  tokens.  The  yacc  generated  parser,
  1422.        yyparse(),  repeatedly calls the lex generated analyzer, yylex(), to
  1423.        process  the  source  program.  The  initial screen display routines
  1424.        were developed with the 'curses' screen library.  
  1425.  
  1426.           The 'C'  source  code  was  then  ported  to  MS-DOS**  (TM), and
  1427.        recompiled  using  the  Lattice***  (TM)  2.15E  compiler, using the
  1428.        'small'  memory model. The screen display functions were modified to
  1429.        use   'int86()',  accessing  the  rom  INT  10H  cursor  positioning
  1430.        functions in the IBM-PC bios.  
  1431.  
  1432.           After it  was  ported  to  MS-DOS it was effectively abandoned by
  1433.        Tom  Poindexter,  and  at this time all attempts to contact him have
  1434.        failed.   I (David Wright) got a copy of it which had been ported to
  1435.        the  Amiga  almost  2  years  ago,  and  have been tracking down the
  1436.        source  code  ever since. In September of 1989 I was finally able to
  1437.        get  the  source  (for  the  IBM/Unix version) and re-port it to the
  1438.  
  1439.  
  1440.                                   Page 23
  1441.  
  1442.  
  1443. Tom Poindexter '85                                      David Wright '89-90
  1444.  
  1445.  
  1446.        Amiga.  At  my  first release it was still text based, but supported
  1447.        the ARP command line handler, stack handler, and file requesters.  
  1448.  
  1449.           My next  release included robots, explosions, and pulses as BOBs,
  1450.        and  2  custom  graphics  screens.  I  also  added   the  ability to
  1451.        pre-compile  the  robots,  so that they may be given out without the
  1452.        source  code  for  competition,  and so that a win/loss ratio can be
  1453.        encoded  into  the  file.  I  also want to create a standalone robot
  1454.        factory  and  test  bench  that  will  let you design your own robot
  1455.        Bob.  
  1456.  
  1457.           Tom was  asking  for  money  to get the source code, but I am not
  1458.        going  to  be  that  strict.  If  you want the latest version of the
  1459.        source,  send  me  a  self-addressed, stamped envelope with a single
  1460.        floppy  also included.  I will copy that latest, released, version I
  1461.        have onto it, and throw in my latest version of CoreWar to boot.  
  1462.  
  1463.         * Unix is a trademark of Bell Telephone Laboratories.  
  1464.         ** MS-DOS is a trademark of Microsoft, Inc.  
  1465.         *** Lattice is a trademark of Lattice, Inc.  
  1466.         **** IBM is a trademark of International Business Machines, Inc.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.                                   Page 24
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.                                 Table of Contents
  1507.  
  1508.           1. Distribution Agreement..................................    1
  1509.           2. Introduction............................................    1
  1510.              2-1. Description........................................    1
  1511.              2-2. Intended Audience..................................    1
  1512.              2-3. Machine requirements...............................    1
  1513.              2-4. User Interface.....................................    2
  1514.           3. Types of Play...........................................    2
  1515.           4. Running CRobots.........................................    2
  1516.              4-1. Command Line Options...............................    2
  1517.              4-2. Examples...........................................    3
  1518.              4-3. Running CRobots from the WorkBench.................    4
  1519.              4-4. Workbench examples.................................    4
  1520.           5. Game Parameters.........................................    4
  1521.              5-1. Battlefield........................................    4
  1522.              5-2. Robot Offense......................................    5
  1523.              5-3. Robot Defense......................................    5
  1524.              5-4. Disabling Opponents................................    6
  1525.              5-5. Sample Display.....................................    7
  1526.           6. CRobots CPU.............................................    8
  1527.           7. CRobots C Compiler......................................    8
  1528.              7-1. Description........................................    8
  1529.              7-2. Features Missing From Standard C...................    8
  1530.              7-3. CRobots Language...................................    9
  1531.              7-4. Compiler Limits....................................   11
  1532.              7-5. Compiler Error & Warning Messages..................   11
  1533.           8. CRobots Intrinsic Function Library......................   12
  1534.           9. CRobots C Program Structure.............................   15
  1535.              9-1. Basic Program Structure............................   15
  1536.              9-2. "sniper.r".........................................   15
  1537.           10. CRobots CPU Architecture and Theory....................   19
  1538.              10-1. Stack usage.......................................   19
  1539.              10-2. Link list.........................................   21
  1540.              10-3. Instruction set...................................   21
  1541.              10-4. Machine level debugging...........................   22
  1542.           11. Implementation notes...................................   23
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.                                        - I -
  1561.  
  1562.