Microsoft KB Archive/63783

How to Scroll Text in an OS/2 Protected Mode COBOL Program

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

3.00 3.00a OS/2

Summary: Microsoft COBOL versions 3.0 and 3.0a protected mode programs can scroll text on the screen by calling the OS/2 API functions VioScrollUp, VioScrollDn, VioScrollLf, and VioScrollRt.

More Information: COBOL versions 3.0 and 3.0a can directly call OS/2 API functions by prefixing their names with a double underscore (&quot;__&quot;) and linking with PCOBOL.LIB and DOSCALLS.LIB. The API functions VioScrollUp, VioScrollDn, VioScrollLf, and VioScrollRt all require the following parameters:

The first four parameters specify the rectangle in which the scrolling is to take place. Any area outside this rectangle is not scrolled. The sixth parameter specifies the character and attribute to use for the new lines or columns created behind the scrolling text. Note that a WORD in COBOL has a picture clause of 9(4) COMP-5 and any parameters not preceded by the word “PTR” must be passed using the BY VALUE clause in the CALL statement. BY REFERENCE is the default for COBOL 3.x. COBOL uses the C calling convention, which pushes parameters on the stack from right to left. The API functions use the Pascal calling convention, which pushes parameters from left to right. Therefore, the parameters must be passed to the API functions in the reverse order of how they are described in the API syntax diagrams. The following program (SCROLL.CBL) displays a message on the screen and allows the user to scroll the message up, down, left, or right using the cursor keys. Any part of the message that is scrolled off the screen is lost. To compile and link the program, enter the following lines at the OS/2 command prompt: pcobol scroll; link /nop scroll adis adisinit adiskey,,,pcobol doscalls;

Code Example
$SET ANS85 IDENTIFICATION DIVISION. PROGRAM-ID. Scroll. DATA DIVISION. WORKING-STORAGE SECTION. *  Coordinates of rectangle to scroll (whole screen). 01 UpperLeftY   PIC 9(4) COMP-5 VALUE 0. 01 UpperLeftX   PIC 9(4) COMP-5 VALUE 0. 01 LowerRightY  PIC 9(4) COMP-5 VALUE 24. 01 LowerRightX  PIC 9(4) COMP-5 VALUE 79. *  Scroll one line at a time. 01 ToScroll     PIC 9(4) COMP-5 VALUE 1. *  Fill new lines/cols with yellow asterisks on red background. 01 FillNew      PIC 9(4) COMP-5 VALUE 20010. *  Default screen group. 01 VideoHandle  PIC 9(4) COMP-5 VALUE 0. *  Used to poll status of/get characters from keyboard. 01 KeyStatus    PIC 99   COMP-X. PROCEDURE DIVISION. *   Clear screen and display message. CALL X&quot;E4&quot;. DISPLAY &quot;SCROLL ME&quot; AT 1235. *   Loop until the enter key is hit. PERFORM UNTIL KeyStatus = 13 *      Loop until user hits a key. MOVE 0 TO KeyStatus PERFORM UNTIL KeyStatus NOT = 0 CALL X&quot;D9&quot; USING KeyStatus END-PERFORM *      Get first byte from keyboard buffer. CALL X&quot;83&quot; USING KeyStatus *      If first byte is null, a cursor key might have been hit. IF KeyStatus = 0 THEN *         Get second byte from keyboard buffer. CALL X&quot;83&quot; USING KeyStatus *         Check if one of the cursor keys was hit, and if so, *         scroll the entire screen one row/column in the *         appropriate direction. EVALUATE KeyStatus WHEN 72 CALL &quot;__VioScrollUp&quot; USING BY VALUE    VideoHandle, BY REFERENCE FillNew, BY VALUE    ToScroll, BY VALUE    LowerRightX, BY VALUE    LowerRightY, BY VALUE    UpperLeftX, BY VALUE    UpperLeftY WHEN 80 CALL &quot;__VioScrollDn&quot; USING BY VALUE    VideoHandle, BY REFERENCE FillNew, BY VALUE    ToScroll, BY VALUE    LowerRightX, BY VALUE    LowerRightY, BY VALUE    UpperLeftX, BY VALUE    UpperLeftY WHEN 75 CALL &quot;__VioScrollLf&quot; USING BY VALUE    VideoHandle, BY REFERENCE FillNew, BY VALUE    ToScroll, BY VALUE    LowerRightX, BY VALUE    LowerRightY, BY VALUE    UpperLeftX, BY VALUE    UpperLeftY WHEN 77 CALL &quot;__VioScrollRt&quot; USING BY VALUE    VideoHandle, BY REFERENCE FillNew, BY VALUE    ToScroll, BY VALUE    LowerRightX, BY VALUE    LowerRightY, BY VALUE    UpperLeftX, BY VALUE    UpperLeftY END-EVALUATE END-IF END-PERFORM. STOP RUN. Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.