*COPY                                                 IK0MAI            01500000
         CHECKVER IK0MAI,4.3                                   @SC90072 01500500
         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
         LM    0,1,=A(IDEFS,LDEFS)  Init. value array          @SC90080 01506000
         LA    14,DEFS       Storage to initialize             @SC90080 01506200
         LR    15,1                                            @SC90080 01506400
         MVCL  14,0          Set up arrays                     @SC90080 01506600
         MVC   S1EOL(2),IS1EOL  Set up prompt                  @SC90173 01507000
         MVI   TRTBL+C' ',1  Set up blank finder               @SC86295 01510000
         MVI   TRMTP,C'&KCONT' Default controller type (TTY)   @SC88309 01511000
         LA    1,ATOE                                          @SC92352 01511200
         LA    2,ETOA                                          @SC92352 01511400
         STM   1,2,AEPTRS    Initially, use normal tables      @SC92352 01511600
         MVC   ETOA,ETOAD    Init translators                  @SC86295 01512000
         MVC   ATOE,ATOED                                      @SC86295 01513000
         L     1,=A(TRNTBL)  1st entry is A/E                  @SC90040 01513300
         MVC   TRNALF(2*LALF),0(1)                             @SC91325 01513600
         MVC   FILALF2,FILALF                                  @SC91325 01513800
         MVC   TETOA,ETOAD                                     @SC87117 01514000
         MVC   TATOE,ATOED                                     @SC87117 01515000
         LA    1,CMD                                           @SC86295 01524000
         ST    1,TAKBUF                                        @SC86295 01525000
         LA    0,((MAXDOF+7)/8)*8  Allow for offset            @SC90264 01526000
         A     0,F64KP       Length of disk buffers            @SC90264 01526060
         SRA   0,3                                             @SC90264 01526120
         DMSFREE DWORDS=(0),ERR=KRMXITS                        @SC90264 01526180
         ST    1,FREED1      1st disk buffer                   @SC90264 01526240
         LA    1,STMGT+MAXDOF(,1) Skip over mgmt stuff & offset@SC90264 01526300
         ST    1,WBUF        Save ptr to buffer itself         @SC90264 01526360
         L     0,F64KP                                         @SC90264 01526420
         SRA   0,3                                             @SC90264 01526480
         DMSFREE DWORDS=(0),ERR=KRMXITS                        @SC90264 01526540
         ST    1,FREED2      2nd disk buffer                   @SC90264 01526600
         LA    1,STMGT(,1)   Skip over management stuff, if any@SC90264 01526660
         ST    1,RBUF        Save ptr to buffer itself         @SC90264 01526720
         LA    1,STMGT       Allow for management stuff        @SC90264 01526780
         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
         LA    1,STMGT(,1)   Skip over management stuff, if any@SC90264 01533500
         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,RIOPTRS+4   Init read length                  @SC90173 01537000
         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
         CLOSF SIMPTR        Close                             @SC91312 01548100
         TM    FL1,DEBUG                                       @SC88119 01548200
         BZ    KRMXITG                                         @SC88119 01548400
         CLOSF LOGPTR        Close                             @SC88119 01548600
KRMXITG  DS    0H                                              @SC88119 01548800
         LM    0,1,FREEDW    Number of dw's, ptr to area       @SC87286 01549000
       DMSFRET DWORDS=(0),LOC=(1)                              @SC86295 01550000
KRMXITQQ ICM   1,15,FREED1   Get 1st buffer area               @SC90264 01554000
         BZ    KRMXITD1      Not assigned                      @SC90264 01554060
         LA    0,((MAXDOF+7)/8)*8  Allow for offset            @SC90264 01554120
         A     0,F64KP       Length of disk buffers            @SC90264 01554180
         SRA   0,3                                             @SC90264 01554240
         DMSFRET DWORDS=(0),LOC=(1)                            @SC90264 01554300
KRMXITD1 ICM   1,15,FREED2   Get 2nd buffer area               @SC90264 01554360
         BZ    KRMXITD2      Not assigned                      @SC90264 01554420
         L     0,F64KP       Length of disk buffers            @SC90264 01554480
         SRA   0,3                                             @SC90264 01554540
         DMSFRET DWORDS=(0),LOC=(1)                            @SC90264 01554600
KRMXITD2 DS    0H                                              @SC90264 01554660
         BAL   14,LDERR      Get error code                    @SC90264 01554720
         RET   MAIN                                            @SC86295 01555000
*                                                                       01556000
KRMXITS  WTEXT '&NOBUFFS'                                      @SC92300 01557000
         B     KRMXITQQ                                                 01558000
*                                                                       01559000
STPTRS   DS    0H            Set up buffer pointers            @SC90264 01560000
         ST    1,TSENT               address of sent files              01564000
         A     1,=A(MAXNSENT*ACTLEN) Length of table           @SC91172 01565000
         ST    1,MSNDBUF     Buffer for extra filespecs        @SC88306 01565590
         AH    1,=Y(MSNDMAX*LFSTF)                             @SC89218 01565700
         ST    1,CBUF        Ptr to CP answer buffer           @SC86295 01566000
         LA    1,512(,1)                                   8*N @SC90264 01567000
         KTRACE SETUP   Get internal trace buffer              @LM91008 01567300
         ST    1,EMSGP       Ptr to saved micro error msg      @SC86295 01568000
         LA    1,LEMSG(1)                                      @SC86295 01569000
         LA    1,MAXDOF(,1)  Leave room for offset, if any     @SC90264 01569500
         ST    1,LOGBUF      Ptr to LOG buffer                 @SC86295 01570000
         LA    1,2(,1)       Room for log labels               @SC91191 01571000
         AH    1,BUFSIZ      Room for data buffer              @SC91191 01571500
         LA    2,TRNSPL(1)   Length of transparency starters   @SC90173 01572000
         BAL   9,KRMPGTB     Round up if necessary             @SC87281 01573000
         ST    1,SIOPTRS                                       @SC90173 01574000
         AH    1,BUFSIZ      Ptr to input buffer               @SC86190 01577000
         LA    2,16(,1)      Extra for I/O stuff               @SC90173 01578000
         BAL   9,KRMPGTB     Round up if necessary             @SC87281 01579000
         ST    1,APKT                                          @SC86190 01583000
         ST    1,RIOPTRS                                       @SC90173 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
