home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / nvdc87 / semicoln / button.src next >
Text File  |  1987-09-22  |  3KB  |  57 lines

  1. {----BUTTON.SRC------------------------------------------------}
  2. {                                                              }
  3. {    by Jeff Duntemann                                         }
  4. {    Turbo Pascal 4.0 -- Last update 9/22/87                   }
  5. {    For "Sense and Semicolons" -- TURBO TECHNIX V1#1          }
  6. {    Adapted from TURBO PASCAL SOLUTIONS by Jeff Duntemann     }
  7. {                                                              }
  8. {    BUTTON.SRC reads the state of the joystick buttons.       }
  9. {    It does *NOT* read the XY value of the joystick itself--  }
  10. {    for that you need assembly language.                      }
  11. {                                                              }
  12. {    The button switch states are maintained in the high 4     }
  13. {    bits of input port $201 for both PC-supported joysticks.  }
  14. {    The bitmap looks like this:                               }
  15. {                                                              }
  16. {    |7 6 5 4 3 2 1 0|                                         }
  17. {     | | | |                                                  }
  18. {     | | |  -----------------> Button #1, joystick #1         }
  19. {     | |  -------------------> Button #2, joystick #1         }
  20. {     |  ---------------------> Button #1, joystick #2         }
  21. {      -----------------------> Button #2, joystick #2         }
  22. {                                                              }
  23. {    The low four bits are used to test the XY values; we      }
  24. {    ignore them here.                                         }
  25. {                                                              }
  26. {    One important thing to keep in mind is that a LOW (0) bit }
  27. {    indicates a button DOWN and a HIGH bit (1) indicates a    }
  28. {    button UP.  That's why we test against a 0 bit rather     }
  29. {    than a 1 bit.                                             }
  30. {--------------------------------------------------------------}
  31.  
  32.  
  33. FUNCTION Button(StickNumber,ButtonNumber : Integer) : Boolean;
  34.  
  35. VAR
  36.   PortValue : Byte;
  37.  
  38. BEGIN
  39.   PortValue := Port[$201];    { Read the joystick I/O port }
  40.   IF StickNumber = 1 THEN     { For joystick #1 }
  41.     IF ButtonNumber = 1 THEN
  42.       Button := ((PortValue AND $10) = 0)
  43.         ELSE
  44.           IF ButtonNumber = 2 THEN
  45.             Button := ((PortValue AND $20) = 0)
  46.               ELSE Button := False
  47.   ELSE
  48.     IF StickNumber = 2 THEN   { For joystick #2 }
  49.       IF ButtonNumber = 1 THEN
  50.         Button := ((PortValue AND $40) = 0)
  51.           ELSE
  52.             IF ButtonNumber = 2 THEN
  53.               Button := ((PortValue AND $80) = 0)
  54.                 ELSE Button := False
  55.     ELSE Button := False
  56. END;
  57.