Microsoft KB Archive/38066

Obtain COBOL Printer Status by Calling ROM BIOS from Assembly

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

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

Summary: To determine the printer status from a COBOL Version 3.0 or 3.0a program, it is necessary to call an assembly routine that performs a ROM BIOS call.

More Information: The COBOL program below calls an assembly routine that executes a ROM BIOS call. The COBOL program demonstrates two methods of reading the status byte that is returned from the ROM CALL. The PRINTCHK.COB program must be compiled with the LITLINK and ANS85 directives. Because these directives are included in the program with the $SET command, it is not necessary to put them on the command line. To compile the COBOL program, use the following: COBOL PRINTCHK.CBL; To compile the assembly program, use the following: MASM PRNTSTAT.ASM; To link the two programs together, use the following: LINK PRINTCHK+PRNTSTAT; The following is a code example:

$SET LITLINK ANS85 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   11-8-88                                printchk.cob       * *  This sample program calls an assembly-language subprogram * *  which checks the printer status. The printer status is   * *  put into PASS-VAR1. The COBOL program must be compiled   * *  with LITLINK and ANS85. The LINK command line is:        * *      LINK PRINTCHK+PRNTSTAT;                               * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  WORKING-STORAGE SECTION. 01 PASS-VAR1         PIC 9(4)     COMP-0 VALUE 0. 01 BYTE-1            PIC 99 COMP-X       VALUE 0. 01 ARRAY-TABLE. 05 ARRAY         PIC 99 COMP-X OCCURS 8. 01 TEMP-VAR          PIC XX. PROCEDURE DIVISION. 0000-MAIN. PERFORM CHECK-PRINTER UNTIL PASS-VAR1 = 0144 STOP RUN. CHECK-PRINTER. MOVE 0 TO PASS-VAR1. CALL &quot;prntstat&quot; USING PASS-VAR1. DISPLAY &quot; &quot; WITH BLANK SCREEN. PERFORM READ-STATUS. PERFORM CALCULATE-STATUS. IF PASS-VAR1 NOT = 0144 DISPLAY &quot;PLEASE CHECK PRINTER AND PRESS RETURN TO CONTINUE&quot; at 0705. ACCEPT TEMP-VAR. READ-STATUS. ************************************************* **    This routine unpacks the AH status byte *** **   into the ARRAY-TABLE, then each bit     *** **   can be checked. *** *************************************************     DISPLAY &quot;EXACT VALUES FROM INTERRUPT&quot;. MOVE PASS-VAR1 TO BYTE-1. CALL X&quot;F5&quot; USING BYTE-1, ARRAY-TABLE. EVALUATE TRUE WHEN ARRAY (1) = 1 DISPLAY &quot;PRINTER NOT BUSY&quot; AT 0202 WHEN ARRAY (2) = 1 DISPLAY &quot;PRINTER ACKNOWLEDGE&quot; AT 0202 WHEN ARRAY (3) = 1 DISPLAY &quot;OUT OF PAPER&quot; AT 0202 WHEN ARRAY (4) = 1 DISPLAY &quot;PRINTER SELECTED&quot; AT 0202 WHEN ARRAY (5) = 1 DISPLAY &quot;PRINTER I/O ERROR&quot; AT 0202 WHEN ARRAY (8) = 1 DISPLAY &quot;PRINTER TIMED-OUT&quot;  AT 0202. CALCULATE-STATUS. ****************************************** ***  This routine works without the    *** *** call X&quot;F5&quot;                        *** ******************************************    DISPLAY &quot;CALCULATED VALUES&quot; AT 0404. EVALUATE PASS-VAR1 WHEN 0144 DISPLAY &quot;PRINTER ONLINE&quot; AT 0505 WHEN 0024 DISPLAY &quot;PRINTER OFFLINE&quot; AT 0505 WHEN 0056 DISPLAY &quot;PRINTER OUT OF PAPER&quot; AT 0505 WHEN 0136 DISPLAY &quot;PRINTER NOT AVAILABLE&quot; AT 0505 WHEN OTHER DISPLAY &quot;PRINTER ERROR&quot;       AT 0505.
 * ;;;;;;;;;; 11-4-88 prntstat.asm ;;;;;;;;;; This code is provided as an example of calling ;;;;;;;;;; interrupts from COBOL. This code is not ;;;;;;;;;; guaranteed by Microsoft in any way. ;;;;;;;;;; ;;;;;;;;;; This routine invokes ROM BIOS call 17 Hex, Function 2, ;;;;;;;;;; to get the printer status. It is called from a ;;;;;;;;;; Microsoft COBOL Version 3.0 program. The call in the ;;;;;;;;;; COBOL program would be: ;;;;;;;;;; CALL “prntstat” USING PASS-VAR. ;;;;;;;;;; Where PASS-VAR is defined in WORKING-STORAGE as ;;;;;;;;;; 01 PASS-VAR PIC 9(4) COMP-0 VALUE 0. ;;;;;;;;;; The COBOL program must be compiled with LITLINK. ;;;;;;;;;; The LINK command line would be: ;;;;;;;;;; LINK cobprog+PRNTSTAT; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; .MODEL large .CODE public prntstat ;make routine visible to COBOL prntstat proc far ;declare it as a far call push bp ;save value of bp mov bp,sp ;load bp with top of stack mov si,[bp+6] ;get address of 1st parameter mov ah,02h ;function 2 - get printer status mov dx,0 int 17h ;make function call mov byte ptr [si+1],ah ;status is placed in low byte of ;1st parameter mov byte ptr [si],0 ;zero out high byte of parameter pop bp ;restore bp ret 12 ;restore stack prntstat endp end

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.