We will create the WTO SVC to queue messages to the console.  When the SVC is called Register 1 contains the address of the message in the bottom three bytes (24 bit address) and the high order byte contains the length of the message.  If the message length is greater than 79 bytes it will be truncated.  If it is less than 79 bytes it will be padded with blanks.

000000                               14 S035WTO  CSECT , 
000000 18CF                          15          LR    R12,R15            SET UP 
                            00000    16          USING S035WTO,R12              BASE REGISTER 
                                     17 *
000002 18B1                          18          LR    R11,R1             COPY PARM REGISTER
000004 58A0 0010      00010          19          L     R10,16             CVT
000008 58A0 A014      00014          20          L     R10,CVTCCB-@CVT(,R10)   CONSOLE COMMUNICATION BLOCK 
                            00000    21          USING @CCB,R10 
                                     22 * 
00000C 12AA                          23          LTR   R10,R10            DO WE HAVE A CONSOLE 
00000E 4780 C09A      0009A          24          BZ    WTO900              NO - GO ABEND 
                                     25 * 
000012                               26 WTO010   DS    0H 
000012 5890 A008      00008          27          L     R9,CCBFMQ          GET FREE BUFFER  
000016 1299                          28          LTR   R9,R9               AND FREE
000018 4780 C0A2      000A2          29          BZ    WTO910               NO - CAN'T DO 
                                     30 * 
00001C 5820 9000      00000          31          L     R2,0(,R9)          FWD CHAIN PTR 
000020 BA92 A008      00008          32          CS    R9,R2,CCBFMQ       REMOVE FROM CHAIN
000024 4770 C012      00012          33          BNZ   WTO010 
                                     34 * 
                            00000    35          USING @CMB,R9

First we locate the CCB and take a message buffer off the free buffer queue.  If no free buffers are available we abend.

000028 D703 9000 9000 00000 00000    37          XC    CMBNEXT,CMBNEXT    CLEAR FWD CHAIN PTR
00002E 181B                          38          LR    R1,R11             COPY
000030 182B                          39          LR    R2,R11                 PARM VALUE
000032 8810 0018      00018          40          SRL   R1,24              SHIFT DOWN TO GET LENGTH
000036 1211                          41          LTR   R1,R1              CHECK LENGTH
000038 4780 C0AA      000AA          42          BZ    WTO920               ERROR IF ZERO
                                     43 *
00003C 5910 C0C0      000C0          44          C     R1,=F'79'          CHECK MAX LENGTH 
000040 4740 C048      00048          45          BL    WTO020
                                     46 *
000044 4110 004F      0004F          47          LA    R1,79
000048                               48 WTO020   DS    0H 
000048 0610                          49          BCTR  R1,0               SUBTRACT ONE FOR EX
00004A 9240 9004      00004          50          MVI   CMBTEXT,C' '       CLEAR OUT MESSAGE BUFFER
00004E D24D 9005 9004 00005 00004    51          MVC   CMBTEXT+1(L'CMBTEXT-1),CMBTEXT
000054 4410 C094      00094          52          EX    R1,WTOEX           COPY IN TEXT

The message text is copied into the free buffer.

000058                               54 WTO030   DS    0H 
000058 4120 A004      00004          55          LA    R2,CCBMBQ          CONSOLE MESSAGE QUEUE
00005C                               56 WTO040   DS    0H 
00005C 5810 2000      00000          57          L     R1,0(,R2)          NEXT ELEMENT
000060 1211                          58          LTR   R1,R1
000062 4780 C06C      0006C          59          BZ    WTO050             BRANCH IF LAST ELEMENT 
                                     60 * 
000066 1821                          61          LR    R2,R1              NEXT ELEMENT 
000068 47F0 C05C      0005C          62          B     WTO040
                                     63 * 
00006C                               65 WTO050   DS    0H 
00006C BA19 2000      00000          66          CS    R1,R9,0(R2)        ADD TO CHAIN
000070 4770 C058      00058          67          BNZ   WTO030             GO TRY AGAIN

The free buffer is placed on the message queue at the end of the chain.

000074 9140 A00C      0000C          69          TM    CCBECB,X'40'       ECB ALREADY POSTED ?
000078 4710 C08A      0008A          70          BO    WTO060               YES - SKIP POST
                                     71 * 
00007C 4110 A00C      0000C          72          LA    R1,CCBECB
                                     73          @CALL POST
000080 58F0 0014      00014          74+         L     R15,20             MVT ADDRESS 
000084 58F0 F028      00028          75+         L     R15,MVTPOST-@MVT(,R15) ROUTINE ADDRESS 
000088 05EF                          76+         BALR  R14,R15
                                     77 * 
00008A                               78 WTO060   DS    0H 
                                     79          @CALL EXIT 
00008A 58F0 0014      00014          80+         L     R15,20             MVT ADDRESS
00008E 58F0 F024      00024          81+         L     R15,MVTEXIT-@MVT(,R15) ROUTINE ADDRESS
000092 05EF                          82+         BALR  R14,R15 
                                     84 * 
000094 D200 9004 B000 00004 00000    85 WTOEX    MVC   CMBTEXT(0),0(R11)  EXECUTED MOVE

If the ECB is already posted we can go ahead and exit now.  If the ECB is not posted we call the Post routine to post it and then we exit the SVC.

00009A                               88 WTO900   DS    0H 
00009A 4110 0123      00123          89          LA    R1,X'123'          NO CONSOLE DEFINED
00009E 47F0 C0B2      000B2          90          B     WTO999
                                     91 *
0000A2                               92 WTO910   DS    0H 
0000A2 4110 0223      00223          93          LA    R1,X'223'
0000A6 47F0 C0B2      000B2          94          B     WTO999 
                                     95 *
0000AA                               96 WTO920   DS    0H
0000AA 4110 0323      00323          97          LA    R1,X'323'
0000AE 47F0 C0B2      000B2          98          B     WTO999
                                     99 * 
0000B2                              100 WTO999   DS    0H 
                                    101          @CALL ABEND 
0000B2 58F0 0014      00014         102+         L     R15,20             MVT ADDRESS
0000B6 58F0 F020      00020         103+         L     R15,MVTABEND-@MVT(,R15) ROUTINE ADDRESS
0000BA 05EF                         104+         BALR  R14,R15

Here are the various abend codes if something goes wrong.

[Next – ]