HEXDUMP  DSECT    1
PLSECT   CSECT    1
         PAGE
         TITLE    'H E X D U M P'
         SYSTEM   SIG7
         REF      BIN2BCD           BINARY TO BCD CONVERSION ROUTINE
         REF      HEX2BCD           HEX TO BCD CONVERSION ROUTINE
         REF      IOBUF
         REF      M:EI              INPUT DCB
         REF      M:EO              OUTPUT DCB
         REF      PRNTBUF           PRINT BUFFER
         REF      RECNUM            LOCATION OF THE RECORD NUMBER
         REF      WRTFPT
         REF      BREAK
         REF      CODE,UNPRINT,TOARG
         REF      PRTBUF
         REF      CCTAB
         REF      SFDEV
         REF      DEVICE
         REF      DEV%IN
*
R0       EQU      0                 ADDRESS COUNTER
R1       EQU      1                 ENTRY REG FOR CONVERSION ROUTINES
R2       EQU      2                 RESULT FROM CONVERSION ROUTINES
R3       EQU      3                 RESULT FROM CONVERSION ROUTINES
R4       EQU      4                 NOTE:R4 IS DESTROYED BY CONVERSIONS
R5       EQU      5                 IOBUF POINTER
R6       EQU      6
R7       EQU      7                 RETURN ADDRESS OF DATA BUFFER
SR1      EQU      8                 ASTERISK FLAG
SR2      EQU      9                 OUTPUT DEVICE INDICATOR
SR3      EQU      10
SR4      EQU      11                USED FOR ALL 'BAL' ROUTINES
D1       EQU      12                PROCEEDING LINE POINTER
D2       EQU      13                CURRENT LINE POINTER
D3       EQU      14                CONTAINS ADDRESS OF PRNTBUF
D4       EQU      15                RECORD SIZE
         USECT    HEXDUMP
         LCI      11
         PSM,R5   *R7
*
         CAL1,1   FPTVFC            RESET VFC
         USECT    PLSECT
FPTVFC   GEN,8,7,17      X'05',0,M:EO
         DATA     0
         USECT    HEXDUMP
         LI,D3    PRNTBUF
         AW,D3    R7                GET ADDRESS OF BUFFER
         LW,D4    WRTFPT+5,R7
         AI,D4    3
         SLS,D4   -2                COMPUTE RECORD SIZE IN WORDS
         LW,R1    TOARG,R7
         CI,R1    8                 IS OUTPUT TO A TERMINAL
         BE       HEX10             YES
         LI,R1    1
         CW,R1    RECNUM,R7
         BNE      HEX10             NOT FIRST REC - SKIP FILE NAME
         CAL1,1   TOPPAGE           SKIP TO TOP OF PAGE
         USECT    PLSECT
TOPPAGE  GEN,8,7,17 X'04',0,M:EO
         USECT    HEXDUMP
         LI,R1    3
         CS,R1    M:EI              INPUT DEVICE TYPE
         BE       HEX10             YES - NO FILE NAME TO PRINT
         USECT    PLSECT
PRTTITLE GEN,8,7,17 X'11',0,M:EO    PRINT TITLE
         DATA     X'34000010'
         PZE      *R3               BUFFER ADDRESS
         PZE      *R1               BUFFER SIZE
         DATA     0                 DISPLACEMENT
KEYTITLE TEXT     'KEY='
ZEROREC  TEXT     'THIS RECORD CONTAINS ALL ZEROES'
NULLKEY  TEXT     'THIS KEYED RECORD IS NULL'
         USECT    HEXDUMP
         LW,R2    ='NAME'
         LW,R3    ='=   '
         STD,R2   *D3               'NAME=' TO PRINT BUFFER
         AI,D3    1
         LI,R1    M:EI+23
         BAL,SR4  UNPRINT           PUT FILE NAME IN BUFFER
         AI,D3    -1                RESTORE BUFFER POINTER
         AI,R2    5                 COMPUTE LENGTH OF LINE
         CAL1,1   FPTFLENM          PRINT THE FILE NAME
         USECT    PLSECT
FPTFLENM GEN,8,7,17 X'11',0,M:EO    PRINT FILE NAME
         DATA     X'34000010'
         PZE      *D3               BUFFER
         PZE      *R2               SIZE
         DATA     0                 BTD
         USECT    HEXDUMP
HEX10    LI,R2    1
         LI,R3    ' '
         STB,R3   *D3
         CAL1,1   FPTFLENM          PRINT BLANK LINE
         LW,R3    DEVICE,R7
         BNEZ     %+2          PCL INPUT DEVICE.
         LW,R3    DEV%IN,R7    SYSTEM INPUT DEVICE.
         CI,R3    7                 IS INPUT FROM ANS TAPE
         BE       PRTREC#           YES - PRINT REC NUMBER
         LI,R3    X'F0'
         LI,R2    X'20'
         CS,R2    M:EI+5            IS FILE KEYED
         BNE      PRTREC#           NO - PRINT REC NUMBER
         LI,R1    20
         LW,R2    =X'40404040'      BLANK PRINT BUFFER
         STW,R2   *D3,R1
         BDR,R1   %-2
         LW,R2    KEYTITLE
         STW,R2   *D3
         AI,D3    1
         LW,R1    M:EI+10
         BAL,SR4  UNPRINT           ENTER KEY IN BUFFER
         AI,D3    -1                RESTORE BUFFER POINTER
         CI,D4    0                 KEYED RECORD NULL
         BE       NULLREC           YES
         LI,R6    0                 BTD
         LW,R5    R2                GET NO. BYTES IN KEY
         AI,R5    12
         SLS,R5   -2                DISP IN BUFFER FOR NEXT ENTRY
         LW,SR2   R5
         SLS,SR2  2
         AI,SR2   14                TOTAL BYTES FOR OUTPUT
         B        RECSIZE           PRINT RECORD SIZE
PRTREC#  LW,R1    RECNUM,R7
         BAL,SR4  BIN2BCD           CONVERT REC# TO BCD
         LI,R1    2
         STW,R3   *D3,R1            STORE REC# IN PRNTBUF
         LCI      2
         LM,R3    RECTEXT           MOVE TEXT TO PRINT BUFFER
         STM,R3   *D3
         LI,SR2   28                LENGTH OF LINE
         LI,R6    2                 BTD
         LI,R5    4                 DISP FOR RECORD NUMBER
RECSIZE  LW,R1    WRTFPT+5,R7       PRINT RECORD SIZE
         BAL,SR4  BIN2BCD           GO-CONVERT SIZE TO EBCDIC
         LCI      2
         STM,R2   *D3,R5            RECORD SIZE TO PRINT BUFFER
         AI,R5    -1
         LW,R3    ='  - '
         STW,R3   *D3,R5
         AI,R5    3
         LCI      2
         LM,R3    BYTES             COMPLETE TEXT IN PRINT BUFFER
         STM,R3   *D3,R5
         CAL1,1   FPTRECSZ          PRINT REC NO OR KEY AND SIZE
         AI,D4    0
         BEZ      RETURN            NULL RECORD
         USECT    PLSECT
FPTRECSZ GEN,8,7,17      X'11',0,M:EO
         DATA     X'34000010'
         PZE      *D3
         PZE      *SR2
         PZE      *R6
RECTEXT  TEXT     '  REC #'
BYTES    TEXT     ' BYTES'
         USECT    HEXDUMP
         LI,R2    1
         LI,R3    ' '
         STB,R3   *D3
         CAL1,1   FPTFLENM          PRINT BLANK LINE
*                                   TEST RECORD FOR ALL ZEROS
         LW,R1    WRTFPT+4,R7       BUFFER ADDRESS
         LW,R2    D4                NOTE THAT D4 CONTAINS REC SIZE
         AI,R2    -1
         MTW,0    *R1,R2            *
         BNEZ     TERMTEST          IF REC NOT = 0; GO TO TERM-TEST
         BDR,R2   %-2
         MTW,0    *R1
         BEZ      ZERORTRN
*
TERMTEST EQU      %
         LI,SR2   4                 SET SWITCH TO USE SHORT BUF FOR TERM
         LW,D1    WRTFPT+4,R7
         SW,D1    R7
         AI,D1    -4                SET POINTER 4 WORDS BACK
         LI,R1    3
         CW,R1    CODE,R7           COMPRESSED INPUT
         BNE      %+2               NO
         LI,D1    PRTBUF-4          SET BUFFER POINTER
         LW,R1    TOARG,R7
         CI,R1    8                 IS OUTPUT TO A TERMINAL
         BE       %+3               YES
         LI,SR2   8                 LP 8 WORDS PER LINE
         AI,D1    -4                SET POINTER 8 WORDS BACK
         LI,R5    0                 INITIALIZE BYTE COUNTER FOR BUFFER
         LW,D2    WRTFPT+4,R7
         AW,D1    R7                ADD DISPLACEMENT TO PROCEEDING LINE
         LI,SR1   0                 RESET ASTERISK FLAG
DUMP2    EQU      %
         MTW,0    BREAK             BREAK KEY HIT
         BEZ      %+4               NO
         LI,R0    0
         STW,R0   BREAK             YES-CLEAR BREAK
         B        RETURN            RETURN
        LI,R1    33
         LW,R2    =X'40404040'      * BLANK PRNTBUF
         STW,R2   *D3,R1
         BDR,R1   %-1
         LW,R1    R0
         BAL,SR4  HEX2BCD           CONVERT ADDRESS TO BCD
         SLD,R2   24
         OR,R3    =X'00404040'      GET RID OF LEADING ZEROES IN ADDRESS
         STD,R2   *D3               PUT ADDRESS INTO PRNT BUFFER
*
         LI,R6    16                LOAD PRNTBUF POINTER
         LW,SR3   SR2
         STW,R5   SFDEV             SAVE INPUT POINTER
DUMP1    LW,R1    *D2,R5            LOAD A WORD FROM THE IOBUFFER
         BAL,SR4  HEX2BCD           CONVERT THE WORD TO BCD
         LI,R4    8                 LOAD THE NUMBER OF DIGITS PER WORD.
         STB,R3   *D3,R6            STORE  A    BYTE OF THE WORD INTO
         SLD,R2   -8                THE PRNTBUF. NOTE THAT THE WORD IS
         AI,R6    -1                STORED LAST-BYTE-FIRST AND THE STORE
         BDR,R4   %-3               BYTE PROCESS MOVES BACKWARD ALONG
         AI,R5    1                 THE LINE. INCREMENT IOBUF POINTER.
         AI,R6    19                ADVANCE PRINT BUFFER POINTER
         CW,R5    D4                IS IOBUF POINTER=SIZE OF RECORD
         BE       PRNT              IF IT IS; PRINT THE LINE, OTHERWISE
         BDR,SR3  DUMP1
*
PRNT     CI,SR1   1                 IS THE ASTERISK FLAG ON
         BNE      %+4               NO; GO PRINT LINE
         LI,R1    5
         LI,R2    C'*'
         STB,R2   *D3,R1            YES; MOVE AN ASTERISK TO LINE.
         AI,R6    -10               MAKE TRUE BYTE COUNT OF LINE
*
         CW,R5    D4                LAST LINE OF RECORD
         BNE      PRNT1             NO
         LI,R1    3
         AND,R1   WRTFPT+5,R7       ANY REMAINING PARTIAL WORD
         BEZ      PRNT1             NO
         SLS,R1   1                 YES-REMOVE CHARS NOT IN RECORD
         AI,R1    -8
         LI,R2    X'40'
         LCW,R1   R1
         AI,R6    -1
         STB,R2   *D3,R6            BLANK OUT CHARS
         BDR,R1   %-2
*
PRNT1    EQU      %
         LW,R1    TOARG,R7          IS THIS A LP DUMP
         CI,R1    8
         BE       PRNT2
         LW,R1    SFDEV             GET CURRENT INPUT POINTER
         SLS,R1   2
         LI,R6    100               START POS FOR EBCDIC
         LI,R2    8                 NO OF WORDS TO PRINT
PRNT4    LI,R4    4                 CHARS PER WORD
PRNT3    LB,R3    *D2,R1            GET INPUT CHAR
         MTH,0    CCTAB,R3          IS IT PRINTABLE
         BGEZ     %+2               YES
         LI,R3    '.'
         STB,R3   *D3,R6            ENTER CHAR IN OUTPUT LINE
         AI,R6    1                 BUMP INPUT POINTER
         AI,R1    1                 BUMP OUTPUT POINTER
         BDR,R4   PRNT3
         MTW,1    SFDEV             INCREMENT WORD POINTER
         CW,D4    SFDEV             ANY MORE WORDS IN RECORD
         BE       PRNT5             NO
         BDR,R2   PRNT4             GO DO NEXT WORD
         B        PRNT2
PRNT5    LI,R1    3
         AND,R1   WRTFPT+5,R7       WAS LAST WORD FULL
         BEZ      PRNT2             YES
         AI,R1    -4                REMOVE TRAILING CHARS
         AW,R6    R1
PRNT2    EQU      %
         CAL1,1   PRINT             PRINT LINE
         USECT    PLSECT
PRINT    GEN,8,7,17 X'11',0,M:EO
         DATA     X'34000010'
         PZE      *D3               BUFFER ADDRESS
         PZE      *R6               LENGTH
         DATA     0                 DISPLACEMENT
         USECT    HEXDUMP
*
         LI,SR1   0                 CLEAR ASTERISK FLAG
         CW,R5    D4                IS POINTER POINTING TO END OF RECORD
         BNE      REENTER
         B        RETURN
*
* THE FOLLOWING CODE COMPARES THE CURRENT LINE TO THE PREVIOUSLY PRINTED
* LINE. IF THE LINES ARE EQUAL PRINT AN ASTERISK ADJACENT TO THE ADDRESS
* FIELD OF THE NEXT UNEQUAL LINE.
*
DUMP4    LW,R1    SR2               4 OR 8 WORDS/LINE (TTY/PRINTER)
         LW,R2    R5                R5 IS THE IOBUF POINTER
DUMP3    LW,R3    *D1,R2            LOAD A WORD FROM THE PRECEDING LINE
         CW,R3    *D2,R2         IS IT=CORRESPONDING WRD OF CURRENT LINE
         BNE      DUMP2             NO; GO & FORM PRNTLINE.
         AI,R2    1                 YES; INCREMENT POINTER.
         CW,R2    D4                IS THIS THE END OF THE RECORD
         BE       DUMP2             YES;GO & FORM PARTIAL-LAST LINE
         BDR,R1   DUMP3             NO; CONTINUE DOING THE COMPARE LOOP
         AW,R5    SR2               MOVE IOBUF POINTER UP TO NEXT LINE
         LI,SR1   1                 LINE WAS DUPLICATED SET ASTERISK FLG
REENTER  AW,R0    SR2               INCREMENT THE ADDRESS COUNTER
         B        DUMP4
*
NULLREC  AI,R2    5                 COMPUTE TOTAL LINE LENGTH
         CAL1,1   FPTFLENM          PRINT KEY NAME
         LI,R1    25
         LI,R3    NULLKEY
         CAL1,1   PRTTITLE          PRINT NULL RECORD MESSAGE
         B        RETURN
*
ZERORTRN LI,R1    31
         LI,R3    ZEROREC
         CAL1,1   PRTTITLE
RETURN   LCI      11
         PLM,R5   *R7
         LI,R0    0
         B        *SR4
         END

