home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / joysdk11 / sample.lst < prev    next >
Encoding:
File List  |  1992-02-18  |  12.5 KB  |  294 lines

  1.  
  2.  
  3.  
  4.                                                                                                                             PAGE   1
  5.                                                                                                                             02-18-92
  6.                                                                                                                             09:49:49
  7.  
  8.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  9.  
  10.       1  /*
  11.       2  Sample C code for reading joystick axis
  12.       3  
  13.       4  Joysticks & gamecards vary in their physical characteristics from one to
  14.       5  another.  For this reason the high state duration of joysticks in their extreme
  15.       6  positions must be predetermined for each joystick & gamecard combinations.
  16.       7  The following program will prompt the user to move the joystick to all its
  17.       8  extreme positions at startup time.  Axis high state duration will be recorded
  18.       9  at these positions for computing joystick position at a later time in the
  19.      10  programs.
  20.      11  */
  21.      12  
  22.      13  #include <conio.h>
  23.      14  #include <stdio.h>
  24.      15  
  25.      16  /*
  26.      17  Declare external functions
  27.      18  */
  28.      19  extern void get_loop_count (void);  /* Assembly language module initialization function*/
  29.      20  extern short read_axis (short);  /* Return axis position count function */
  30.      21  
  31.      22  /*
  32.      23  Declare local functions
  33.      24  */
  34.      25  short compute_axis (short, short, short);  /* Compute axis coordinate */
  35.      26  void display_coordinate (void);  /* Display joystick coordinate */
  36.      27  
  37.      28  /*
  38.      29  Declare variable
  39.      30  */
  40.      31  short stick_a_min_x;  /* Minimum high state duration for X axis of joystick A */
  41.      32  short stick_a_max_x;  /* Maximun high state duration for X axis of joystick A */
  42.      33  short stick_a_range_x;    /* Joystick A - X axis travel range */
  43.      34  short stick_a_min_y;  /* Minimum high state duration for Y axis of joystick A */
  44.      35  short stick_a_max_y;  /* Maximum high state duration for Y axis of joystick A */
  45.      36  short stick_a_range_y;    /* Joystick A - Y axis travel range */
  46.      37  short stick_b_min_x;  /* Minimum high state duration for X axis of joystick B */
  47.      38  short stick_b_max_x;  /* Maximun high state duration for X axis of joystick B */
  48.      39  short stick_b_range_x;    /* Joystick B - X axis travel range */
  49.      40  short stick_b_min_y;  /* Minimum high state duration for Y axis of joystick B */
  50.      41  short stick_b_max_y;  /* Maximum high state duration for Y axis of joystick B */
  51.      42  short stick_b_range_y;    /* Joystick B - Y axis travel range */
  52.      43  
  53.      44  main ()
  54.      45  {
  55.      46      /* Initialize assembly language module by calling get_loop_count */
  56.      47      get_loop_count ();
  57.      48  
  58.      49      /* Joystick A */
  59.      50      printf ("Push spacebar when joystick A is farthest to left\n");
  60.      51      /* Wait for spacebar pressed */
  61.      52      while (getch () != 0x20)
  62.      53          ;
  63.      54      /* Spacebar pressed, read joystick A - X axis */
  64.      55      stick_a_min_x = read_axis (0);
  65.      56  
  66.  
  67.  
  68.  
  69.                                                                                                                             PAGE   2
  70.                                                                                                                             02-18-92
  71.                                                                                                                             09:49:49
  72.  
  73.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  74.  
  75.      57      printf ("Push spacebar when joystick A is farthest to right\n");
  76.      58      /* Wait for spacebar pressed */
  77.      59      while (getch () != 0x20)
  78.      60          ;
  79.      61      /* Spacebar pressed, read joystick A - X axis */
  80.      62      stick_a_max_x = read_axis (0);
  81.      63  
  82.      64      /* Compute joystick A - X axis travel range */
  83.      65      stick_a_range_x = stick_a_max_x - stick_a_min_x;
  84.      66  
  85.      67  
  86.      68      printf ("Push spacebar when joystick A is farthest to top\n");
  87.      69      /* Wait for spacebar pressed */
  88.      70      while (getch () != 0x20)
  89.      71          ;
  90.      72      /* Spacebar pressed, read joystick A - Y axis */
  91.      73      stick_a_min_y = read_axis (1);
  92.      74  
  93.      75      printf ("Push spacebar when joystick A is farthest to bottom\n");
  94.      76      /* Wait for spacebar pressed */
  95.      77      while (getch () != 0x20)
  96.      78          ;
  97.      79      /* Spacebar pressed, read joystick A - Y axis */
  98.      80      stick_a_max_y = read_axis (1);
  99.      81  
  100.      82      /* Compute joystick A - Y axis travel range */
  101.      83      stick_a_range_y = stick_a_max_y - stick_a_min_y;
  102.      84  
  103.      85  
  104.      86  
  105.      87      /* Joystick B */
  106.      88      printf ("Push spacebar when joystick B is farthest to left\n");
  107.      89      /* Wait for spacebar pressed */
  108.      90      while (getch () != 0x20)
  109.      91          ;
  110.      92      /* Spacebar pressed, read joystick B - X axis */
  111.      93      stick_b_min_x = read_axis (2);
  112.      94  
  113.      95      printf ("Push spacebar when joystick B is farthest to right\n");
  114.      96      /* Wait for spacebar pressed */
  115.      97      while (getch () != 0x20)
  116.      98          ;
  117.      99      /* Spacebar pressed, read joystick B - X axis */
  118.     100      stick_b_max_x = read_axis (2);
  119.     101  
  120.     102      /* Compute joystick B - X axis travel range */
  121.     103      stick_b_range_x = stick_b_max_x - stick_b_min_x;
  122.     104  
  123.     105  
  124.     106      printf ("Push spacebar when joystick B is farthest to top\n");
  125.     107      /* Wait for spacebar pressed */
  126.     108      while (getch () != 0x20)
  127.     109          ;
  128.     110      /* Spacebar pressed, read joystick B - Y axis */
  129.     111      stick_b_min_y = read_axis (3);
  130.     112  
  131.  
  132.  
  133.  
  134.                                                                                                                             PAGE   3
  135.                                                                                                                             02-18-92
  136.                                                                                                                             09:49:49
  137.  
  138.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  139.  
  140.     113      printf ("Push spacebar when joystick B is farthest to bottom\n");
  141.     114      /* Wait for spacebar pressed */
  142.     115      while (getch () != 0x20)
  143.     116          ;
  144.     117      /* Spacebar pressed, read joystick B - Y axis */
  145.     118      stick_b_max_y = read_axis (3);
  146.     119  
  147.     120      /* Compute joystick B - Y axis travel range */
  148.     121      stick_b_range_y = stick_b_max_y - stick_b_min_y;
  149.     122  
  150.     123  
  151.     124  
  152.     125      /* Display joystick coordinate */
  153.     126      while (!kbhit ())
  154.     127            display_coordinate ();
  155.     128      /* Flush keyboard buffer before quitting */
  156.     129      if (getch () == 0)
  157.     130          getch ();
  158.     131  }
  159.     132  
  160.     133  
  161.     134  /*
  162.     135  Display all 4 joystick coordinates from a range of 0 to 100
  163.     136  */
  164.     137  
  165.     138  void display_coordinate ()
  166.     139  {
  167.     140      short stick_a_x, stick_a_y, stick_b_x, stick_b_y;
  168.     141  
  169.     142      stick_a_x = read_axis (0);
  170.     143      if (stick_a_x < stick_a_min_x)
  171.     144          stick_a_x = stick_a_min_x;
  172.     145      else
  173.     146          if (stick_a_x > stick_a_max_x)
  174.     147              stick_a_x = stick_a_max_x;
  175.     148      if (stick_a_range_x == 0)
  176.     149          printf ("         0");
  177.     150      else
  178.     151          printf ("%10d", compute_axis (stick_a_x, stick_a_min_x, stick_a_range_x));
  179.     152  
  180.     153      stick_a_y = read_axis (1);
  181.     154      if (stick_a_y < stick_a_min_y)
  182.     155          stick_a_y = stick_a_min_y;
  183.     156      else
  184.     157          if (stick_a_y > stick_a_max_y)
  185.     158              stick_a_y = stick_a_max_y;
  186.     159      if (stick_a_range_y == 0)
  187.     160          printf ("         0");
  188.     161      else
  189.     162          printf ("%10d", compute_axis (stick_a_y, stick_a_min_y, stick_a_range_y));
  190.     163  
  191.     164  
  192.     165      stick_b_x = read_axis (2);
  193.     166      if (stick_b_x < stick_b_min_x)
  194.     167          stick_b_x = stick_b_min_x;
  195.     168      else
  196.  
  197.  
  198.  
  199.                                                                                                                             PAGE   4
  200.                                                                                                                             02-18-92
  201.                                                                                                                             09:49:49
  202.  
  203.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  204.  
  205.     169          if (stick_b_x > stick_b_max_x)
  206.     170              stick_b_x = stick_b_max_x;
  207.     171      if (stick_b_range_x == 0)
  208.     172          printf ("         0");
  209.     173      else
  210.     174          printf ("%10d", compute_axis (stick_b_x, stick_b_min_x, stick_b_range_x));
  211.     175  
  212.     176      stick_b_y = read_axis (3);
  213.     177      if (stick_b_y < stick_b_min_y)
  214.     178          stick_b_y = stick_b_min_y;
  215.     179      else
  216.     180          if (stick_b_y > stick_b_max_y)
  217.     181              stick_b_y = stick_b_max_y;
  218.     182      if (stick_b_range_y == 0)
  219.     183          printf ("         0");
  220.     184      else
  221.     185          printf ("%10d\n", compute_axis (stick_b_y, stick_b_min_y, stick_b_range_y));
  222.     186  }
  223.  
  224.  
  225. display_coordinate  Local Symbols
  226.  
  227. Name                      Class   Type              Size   Offset  Register
  228.  
  229. stick_b_y . . . . . . . . auto                             -0008 
  230. stick_a_y . . . . . . . . auto                             -0006 
  231. stick_b_x . . . . . . . . auto                             -0004 
  232. stick_a_x . . . . . . . . auto                             -0002 
  233.  
  234.     187  
  235.     188  
  236.     189  /*
  237.     190  Compute axis coordinate from a range of 0 to 100
  238.     191  */
  239.     192  short compute_axis (axis, min, range)
  240.     193  short axis, min, range;
  241.     194  {
  242.     195      return (((long) 100 * (long) (axis - min)) / (long) range);
  243.     196  }
  244.  
  245.  
  246. compute_axis  Local Symbols
  247.  
  248. Name                      Class   Type              Size   Offset  Register
  249.  
  250. axis. . . . . . . . . . . param                             0004
  251. min . . . . . . . . . . . param                             0006
  252. range . . . . . . . . . . param                             0008
  253.  
  254.  
  255. Global Symbols
  256.  
  257. Name                      Class   Type              Size   Offset  
  258.  
  259. compute_axis. . . . . . . global  near function      ***    02a3
  260. display_coordinate. . . . global  near function      ***    0147
  261.  
  262.  
  263.  
  264.                                                                                                                             PAGE   5
  265.                                                                                                                             02-18-92
  266.                                                                                                                             09:49:49
  267.  
  268.                                                                                                    Microsoft C Compiler Version 5.10
  269.  
  270.  
  271. Global Symbols
  272.  
  273. Name                      Class   Type              Size   Offset  
  274.  
  275. get_loop_count. . . . . . extern  near function      ***     ***
  276. getch . . . . . . . . . . extern  near function      ***     ***
  277. kbhit . . . . . . . . . . extern  near function      ***     ***
  278. main. . . . . . . . . . . global  near function      ***    0000
  279. printf. . . . . . . . . . extern  near function      ***     ***
  280. read_axis . . . . . . . . extern  near function      ***     ***
  281. stick_a_max_x . . . . . . common  int                  2     ***
  282. stick_a_max_y . . . . . . common  int                  2     ***
  283. stick_a_min_x . . . . . . common  int                  2     ***
  284. stick_a_min_y . . . . . . common  int                  2     ***
  285. stick_a_range_x . . . . . common  int                  2     ***
  286. stick_a_range_y . . . . . common  int                  2     ***
  287. stick_b_max_x . . . . . . common  int                  2     ***
  288. stick_b_max_y . . . . . . common  int                  2     ***
  289. stick_b_min_x . . . . . . common  int                  2     ***
  290. stick_b_min_y . . . . . . common  int                  2     ***
  291. stick_b_range_x . . . . . common  int                  2     ***
  292. stick_b_range_y . . . . . common  int                  2     ***
  293.  
  294. Code size = 02ce (718)
  295. Data size = 01dd (477)
  296. Bss size  = 0000 (0)
  297.  
  298. No errors detected
  299.