*COPY                                                 IK0MAI            01500000
         TITLE 'Kermit-370 main code'                          @SC86268 01501000
KERMIT   ENTER MAIN                                            @SC86295 01502000
         STM   0,1,ORGR0     Save R0,R1                        @SC87253 01503000
* Initialize STORAG section                                             01504000
         OI    FL5,TIMF      Set timer on                      @SC86355 01505000
         MVC   DEFS(LDEFS),IDEFS Init. values                  @SC86295 01506000
         MVC   S1DATA,S1XON  Series/1 orders                   @SC86295 01507000
         LA    1,S1XON                                         @SC87274 01508000
         ST    1,S1XOPL      Set up prompt plist               @SC87274 01509000
         MVI   TRTBL+C' ',1  Set up blank finder               @SC86295 01510000
         MVI   TRMTP,C'T'    Assume going via TTY line         @SC87166 01511000
         MVC   ETOA,ETOAD    Init translators                  @SC86295 01512000
         MVC   ATOE,ATOED                                      @SC86295 01513000
         MVC   TETOA,ETOAD                                     @SC87117 01514000
         MVC   TATOE,ATOED                                     @SC87117 01515000
*        MVC   OFF80(128),LOCASE                               @SC87253 01516000
*        MVC   OFF80+128(128),LOCASE                           @SC87253 01517000
         LA    1,255                                           @SC86295 01518000
         STC   1,UPCASE(1)                                     @SC86295 01519000
         BCT   1,*-4                                           @SC86295 01520000
         MVC   UPCASE+C'a'(9),ATOE+AA                          @SC86295 01521000
         MVC   UPCASE+C'j'(9),ATOE+AJ                          @SC86295 01522000
         MVC   UPCASE+C's'(8),ATOE+AS                          @SC86295 01523000
         LA    1,CMD                                           @SC86295 01524000
         ST    1,TAKBUF                                        @SC86295 01525000
         SR    1,1                                             @SC86295 01526000
         LA    5,4095        For page boundaries...            @SC87281 01527000
         BAL   14,STPTRS     Get length of storage needed      @SC86295 01528000
         LA    0,7(1,5)      Round up                          @SC87281 01529000
         SRA   0,3                                             @SC86295 01530000
         ST    0,FREEDW      Number of dw's to get             @SC86295 01531000
       DMSFREE DWORDS=(0),ERR=KRMXITS                          @SC86295 01532000
         ST    1,FREEPTR     Save start of area                @SC87286 01533000
         BAL   9,KRMPG       Round up to next page             @SC87281 01534000
         BAL   14,STPTRS     Set up ptrs                       @SC86295 01535000
         LH    1,BUFSIZ                                        @SC86295 01536000
         ST    1,TYRDPL+4    Set up read lists                 @SC86295 01537000
         A     1,F3                                            @SC86295 01538000
         ST    1,S1RDPL+4                                      @SC86295 01539000
         L     1,LOGBUF                                        @SC86295 01540000
         MVI   1(1),C':'     Set up prefix                     @SC86190 01541000
         KCALL SETMSG,1,E=KRMXITF Get user's settings                   01542000
         KCALL SPARSET                                         @SC86152 01543000
         MVC   DATL,F0                                         @SC87012 01544000
         KCALL SPAR          Set defaults for other Kermit     @SC87012 01545000
         KCALL USNTRF        Call main loop                    @SC87117 01546000
*                                                                       01547000
KRMXITF  KCALL SETMSG,4      System-dependent clean-up         @SC86316 01548000
         LM    0,1,FREEDW    Number of dw's, ptr to area       @SC87286 01549000
       DMSFRET DWORDS=(0),LOC=(1)                              @SC86295 01550000
         TM    FL1,DEBUG                                       @SC86295 01551000
         BZ    KRMXITQQ                                        @SC86295 01552000
         CLOSF LOGPTR        Close                             @SC86295 01553000
KRMXITQQ BAL   14,LDERR      Get error code                    @SC87117 01554000
         RET   MAIN                                            @SC86295 01555000
*                                                                       01556000
KRMXITS  WTEXT 'Unable to allocate buffers'                             01557000
         B     KRMXITQQ                                                 01558000
*                                                                       01559000
STPTRS   ST    1,RBUF        Addr of first buffer                       01560000
         A     1,F64KP               Second buffer                      01561000
         ST    1,WBUF                Away from first                    01562000
         A     1,F64KP                                                  01563000
         ST    1,TSENT               address of sent files              01564000
         AH    1,=Y(MAXNSENT*LFID) Length of table             @SC86190 01565000
         ST    1,CBUF        Ptr to CP answer buffer           @SC86295 01566000
         A     1,F256                                          @SC86295 01567000
         ST    1,EMSGP       Ptr to saved micro error msg      @SC86295 01568000
         LA    1,LEMSG(1)                                      @SC86295 01569000
         ST    1,LOGBUF      Ptr to LOG buffer                 @SC86295 01570000
         LA    1,2(1)        Data record overlays S/1 orders   @SC86190 01571000
         LA    2,S1ORDL(1)                                     @SC87281 01572000
         BAL   9,KRMPGTB     Round up if necessary             @SC87281 01573000
         ST    1,S1WRPL                                        @SC86295 01574000
         LA    1,S1ORDL(1)   Ptr to output data                @SC86190 01575000
         ST    1,TYWRPL                                        @SC86190 01576000
         AH    1,BUFSIZ      Ptr to input buffer               @SC86190 01577000
         LA    2,3(1)                                          @SC87281 01578000
         BAL   9,KRMPGTB     Round up if necessary             @SC87281 01579000
         LR    2,1                                             @SC86190 01580000
         LA    1,3(1)        Allow S/1 screen info             @SC87281 01581000
         ST    2,S1RDPL                                        @SC86295 01582000
         ST    1,APKT                                          @SC86190 01583000
         ST    1,TYRDPL      Read plist                        @SC86295 01584000
         AH    1,BUFSIZ      Ptr to output holding buffer      @SC86190 01585000
         ST    1,ASPKT                                         @SC86190 01586000
         ST    1,AASPKT                                        @SC86190 01587000
         LA    2,7(1)        Skip over extended header         @SC86190 01588000
         ST    2,ASDATA                                        @SC86190 01589000
         AH    1,BUFSIZ      Ptr to input decoding buffer      @SC86190 01590000
         ST    1,ARPKT                                         @SC86190 01591000
         AH    1,BUFSIZ      Ptr to take table                 @SC86190 01592000
         KSYSBUF ,           Other buffers                     @SC86355 01593000
         BR    14            Return with R1 -> end             @SC86295 01594000
*                                                                       01595000
* Round up R1 to next page if (R1)-(R2) would cross boundary.  @SC87281 01596000
* (R5) = page size - 1 (should be 4095), return to (R9)        @SC87281 01597000
KRMPGTB  AH    2,BUFSIZ      Tentative end of buffer           @SC87281 01598000
KRMPGT   BCTR  2,0           Last byte                         @SC87281 01599000
         XR    2,1           Same page as first?               @SC87281 01600000
         NR    2,5                                             @SC87281 01601000
         BZR   9             Same page, ok                     @SC87281 01602000
KRMPG    AR    1,5           Round up to next page             @SC87281 01603000
         OR    1,5                                             @SC87281 01604000
         XR    1,5                                             @SC87281 01605000
         BR    9                                                        01606000
         LOCALS ,                                              @SC86295 01607000
KERMIT   EXIT                                                           01608000
