Microsoft KB Archive/36076

From BetaArchive Wiki

How to CALL the Microsoft Mouse from COBOL 3.0

PSS ID Number: Q36076 Article last modified on 04-20-1993

3.00 | 3.00 MS-DOS | OS/2

The information in this article applies to:
- Microsoft COBOL for MS-DOS and OS/2, version 3.0

Summary: The program example below shows how to call the Microsoft Mouse from COBOL Version 3.0. Each mouse call procedure uses the CALL X“84” Microsoft COBOL extension routine, which is documented in the “Microsoft COBOL Compiler 3.0: Operating Guide” on Page 8-4. The first call to the mouse must be the call to initialize it. The mouse must then be turned on before the mouse’s location and button status can be queried. Specific information regarding the mouse functions can be found in the “Microsoft Mouse Programmer’s Reference Guide,” which is sold separately. You can obtain this guide by calling Microsoft Press or Microsoft International Customer Service (international calls only).

More Information: All mouse calls are made by putting the appropriate data into the AX, BX, CX, and DX registers and calling DOS interrupt 51. The example below loads values into Mouse-1 through Mouse-4 to be passed to the registers, loads the interrupt number (51) into Mouse-Int, and sets the Mouse-Flag. The Mouse-Flag (Hex value FF) specifies that all values in Mouse-1 through Mouse-4 are to be passed by reference. The following program may be compiled with no special compiler directives. COBOL versions earlier than 3.0 do not provide a statement like X“84” to make DOS function calls. The COBOL Tools package in COBOL Version 2.2 (provided as a separate product for COBOL 2.1) provides a CALL “CBMOUSE” routine to make mouse calls. The following is a code example:

  $set ans85
   SPECIAL-NAMES.
   CONSOLE IS CRT.
   DATA DIVISION.
   working-storage section.
   01 Mouse-Info.
      02 Mouse-1       pic 9(4)     comp-x.
      02 Mouse-2       pic 9(4)     comp-x.
      02 Mouse-3       pic 9(4)     comp-x.
      02 Mouse-4       pic 9(4)     comp-x.
      02 Mouse-flag    pic x        value X"FF".
      02 Mouse-INT     pic x        comp-x value 51.
      02 LeftButton    pic x.
      02 RightButton   pic x.
      02 Mouse-X       pic 9(4)     comp-x.
      02 Mouse-Y       pic 99       comp-x.
      02 Mouse-Line    pic 99.
      02 Mouse-Col     pic 99.
   PROCEDURE DIVISION.
   MAIN.
      Display Spaces upon CRT.
      Perform Mouse-Init.
      Perform Mouse-On.
      Display "Left " at 1003.
      Display "Right" at 1103.
      Display "Coordinates" at 0915.
      Display "Line/Column" at 0940.
      Perform until LeftButton=1 and RightButton=1
        Perform Mouse-Press
        Display LeftButton at 1010
        Display RightButton at 1110
        Display Mouse-y at 1015
        Display Mouse-x at 1115
        Display Mouse-Line at 1040
        Display Mouse-col at 1140
      end-perform.
      stop run.
   Mouse-Init.
       MOVE 0 to Mouse-1.
       CALL X"84" using Mouse-int, Mouse-flag, Mouse-1,
               Mouse-2, Mouse-3, Mouse-4.
   Mouse-On.
       MOVE 1 to Mouse-1.
       CALL X"84" using Mouse-int, Mouse-flag, Mouse-1,
               Mouse-2, Mouse-3, Mouse-4.
   Mouse-Off.
       MOVE 2 to Mouse-1.
       CALL X"84" using Mouse-int, Mouse-flag, Mouse-1,
               Mouse-2, Mouse-3, Mouse-4.
   Mouse-Press.
       MOVE 3 to Mouse-1.
       CALL X"84" using Mouse-int, Mouse-flag, Mouse-1,
                  Mouse-2, Mouse-3, Mouse-4.
       MOVE 0 to LeftButton.
       MOVE 0 to RightButton.
       IF Mouse-2 = 1 or Mouse-2 = 3 THEN
           MOVE 1 to LeftButton.
       IF Mouse-2 = 2 or Mouse-2 = 3 THEN
           MOVE 1 to RightButton.
       MOVE Mouse-3 to Mouse-x
       MOVE Mouse-4 to Mouse-y
       Compute Mouse-Line = Mouse-4 / 8
       Compute Mouse-Col = Mouse-3 / 8.

Additional reference words: 3.00 Copyright Microsoft Corporation 1993.