Microsoft KB Archive/62268

COBOL Program to Get Position of Cursor in DOS or OS/2

PSS ID Number: Q62268 Article last modified on 06-14-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: Microsoft COBOL versions 3.00 and 3.00a can call an interrupt to get the position of the cursor. These versions of COBOL can call interrupts via the special subprogram X“84”. The interrupt in question is 10Hex, function 03Hex. It requires the following registers for input: AH (upper byte of AX) = 03H BH (upper byte of BX) = page The interrupt returns information in the following registers: CH (upper byte of CX) = starting line for cursor CL (lower byte of CX) = ending line for cursor DH (upper byte of DX) = row (y coordinate) DL (lower byte of DX) = column (x coordinate) AH holds the function number and BH the display page. A separate cursor is maintained for each display page and the position of each can be gotten independently with this function regardless of which page is currently visible. The maximum values for CH and CL depend on the current display mode, but the top line of the cursor is always 0. The maximum values for DL and DH also depend on the current display mode, but the upper-left corner of the screen is always (0,0). This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: For more information about calling interrupts from COBOL 3.00 and 3.00a, see Pages 8-4 and 8-5 of the “Microsoft COBOL Compiler 3.0: Operating Guide” included with the product. For more information about interrupt 10H, function 03H, see Pages 502 and 503 of “Advanced MS-DOS Programming, Second Edition” by Ray Duncan (Microsoft Press, 1988). The following program reports the location of the cursor after a message is displayed on the screen. As with any DISPLAY, the cursor will be located one character to right of the message.

DATA DIVISION. WORKING-STORAGE SECTION. 01 AX. *  Function 03H 05 A-H     PIC 99   COMP-X VALUE 3. 05 A-L     PIC 99   COMP-X. 01 BX. *  Display page 0 05 B-H     PIC 99   COMP-X VALUE 0. 05 B-L     PIC 99   COMP-X. 01 CX. 05 C-H     PIC 99   COMP-X. 05 C-L     PIC 99   COMP-X. 01 DX. 05 D-H     PIC 99   COMP-X. 05 D-L     PIC 99   COMP-X. * Initialize to interrupt 10H 01 Interrupt  PIC X           VALUE X&quot;10&quot;. * Load actual registers with passed parameters 01 Flag       PIC X           VALUE X&quot;FF&quot;. PROCEDURE DIVISION. *   Clear the screen CALL X&quot;E4&quot;. DISPLAY &quot;This message starts at row 12 column 10 and it -            is 119 characters long so it will leave the -           cursor at row 13 column 49.&quot; AT 1210. *   Call the interrupt to get position of the cursor CALL X&quot;84&quot; USING Interrupt, Flag, AX, BX, CX, DX. *   Add 1 to coordinates so they will be reported in range of  *    (1-25),(1-80), the coordinate range for DISPLAYs, instead *   (0-24),(0-79)       COMPUTE D-H = D-H + 1. COMPUTE D-L = D-L + 1. *   Display coordinates DISPLAY &quot;Row   =&quot; AT 1501. DISPLAY D-H       AT 1510. DISPLAY &quot;Column =&quot; AT 1601. DISPLAY D-L       AT 1610. STOP RUN. Copyright Microsoft Corporation 1990.