Advertisement
Guest User

libjvs sample

a guest
Jan 12th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. // Include the header and declare the I/O unit's handle pointer.
  2. #include "libjvs/jvs.h"
  3.  
  4. static JVS_IO* jvs_io;
  5.  
  6. // Opening the JVS communication and getting the handle for the first I/O unit.
  7.   if(!jvs_setup(jvs_port_name))
  8.     return 0;
  9.   if(jvs_io_count() < 1) // Check if we have at least 1 I/O unit.
  10.     return 0;
  11.  
  12.   jvs_io = jvs_io_get(1); // Get handle for I/O unit 1.
  13. //..........
  14.  
  15. // Closing the JVS communication.
  16.   jvs_shutdown();
  17. //..........
  18.  
  19. // Typical per-frame update function.
  20.   if(!jvs_io_update(jvs_io->node, jvs_io)) // Update the I/O unit handle structure.
  21.     return 0;
  22.   if(!jvs_io->sw.has) // Check that the I/O unit has player input switches
  23.     return 0;
  24.   if(jvs_io->sw.buttons < 10) // Check that the I/O unit gives each player at least 10 switches (1 lever + 4 buttons + start + service)
  25.     return 0;
  26.  
  27.   int j = 0;
  28.   if(jvs_io->sw.data[j] & 0x80) {
  29.     // ADD CODE: Handle test button
  30.   }
  31.   j++;
  32.   for(int i = 0; i < jvs_io->sw.players; i++) {
  33.     for(int l = 0; l < 10; l++) {
  34.       if(l >= jvs_io->sw.buttons)
  35.         break;
  36.       if(jvs_io->sw.data[j + (l >> 3)] & (0x80 >> (l & 7))) {
  37.         // ADD CODE: Handle switch l from player i
  38.       }
  39.     }
  40.     j += (jvs_io->sw.buttons + 7) >> 3;
  41.   }
  42.  
  43.   if(jvs_io->coin.has) {
  44.     for(int i = 0; i < jvs_io->coin.slots; i++) {
  45.       if(jvs_io->coin.count[i] & 0xC000) // Coin slot is not functional
  46.         continue;
  47.       // ADD CODE: Add (jvs_io->coin.count[i] & 0x3FFF) coins
  48.  
  49.       jvs_io->coin.subtract[i] = jvs_io->coin.count[i] & 0x3FFF; // Remove coins that were processed.
  50.     }
  51.   }
  52. //..........
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement