home *** CD-ROM | disk | FTP | other *** search
- {----BUTTON.SRC------------------------------------------------}
- { }
- { by Jeff Duntemann }
- { Turbo Pascal 4.0 -- Last update 9/22/87 }
- { For "Sense and Semicolons" -- TURBO TECHNIX V1#1 }
- { Adapted from TURBO PASCAL SOLUTIONS by Jeff Duntemann }
- { }
- { BUTTON.SRC reads the state of the joystick buttons. }
- { It does *NOT* read the XY value of the joystick itself-- }
- { for that you need assembly language. }
- { }
- { The button switch states are maintained in the high 4 }
- { bits of input port $201 for both PC-supported joysticks. }
- { The bitmap looks like this: }
- { }
- { |7 6 5 4 3 2 1 0| }
- { | | | | }
- { | | | -----------------> Button #1, joystick #1 }
- { | | -------------------> Button #2, joystick #1 }
- { | ---------------------> Button #1, joystick #2 }
- { -----------------------> Button #2, joystick #2 }
- { }
- { The low four bits are used to test the XY values; we }
- { ignore them here. }
- { }
- { One important thing to keep in mind is that a LOW (0) bit }
- { indicates a button DOWN and a HIGH bit (1) indicates a }
- { button UP. That's why we test against a 0 bit rather }
- { than a 1 bit. }
- {--------------------------------------------------------------}
-
-
- FUNCTION Button(StickNumber,ButtonNumber : Integer) : Boolean;
-
- VAR
- PortValue : Byte;
-
- BEGIN
- PortValue := Port[$201]; { Read the joystick I/O port }
- IF StickNumber = 1 THEN { For joystick #1 }
- IF ButtonNumber = 1 THEN
- Button := ((PortValue AND $10) = 0)
- ELSE
- IF ButtonNumber = 2 THEN
- Button := ((PortValue AND $20) = 0)
- ELSE Button := False
- ELSE
- IF StickNumber = 2 THEN { For joystick #2 }
- IF ButtonNumber = 1 THEN
- Button := ((PortValue AND $40) = 0)
- ELSE
- IF ButtonNumber = 2 THEN
- Button := ((PortValue AND $80) = 0)
- ELSE Button := False
- ELSE Button := False
- END;