home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / b / krthex.mac < prev    next >
Text File  |  2020-01-01  |  10KB  |  292 lines

  1.     .title    KRTHEX    Create .SAV file from its .HEX equivalent
  2.     .ident    "V03.63"
  3.  
  4. ; /63/    27-Sep-97  Billy Youdelman  V03.63
  5. ;
  6. ;    This is a spiffed up K11HEX.MAC
  7.  
  8. ;    25-Oct-84  11:14:41  Brian Nelson
  9.  
  10. ; This program is meant to be used when no better means exist (such as a
  11. ; floppy disk drive, removable media drive, etc) to copy Kermit on to the
  12. ; target system.  Instead, any convenient local system, such as a pc, may
  13. ; be used by connecting it to the PDP-11 console port and then talking to
  14. ; the RT-11 system via a comm program with which files may be copied over
  15. ; to the PDP-11.  The process works like this:
  16. ;
  17. ; 1.  Get this file (KRTHEX.MAC) and at least one of KRT.HEX or KRTTSX.HEX
  18. ; on to the local (pc) system.  You can also include as much as you want,
  19. ; or later after Kermit is up on the PDP-11, connect to the source and get
  20. ; the rest direct.  The only binary (8-bit) material in the entire KRT
  21. ; distribution are the .SAV files - anything else may be transfered using
  22. ; this method (the stock RT-11 terminal handler strips the hi bit).
  23. ;
  24. ; 2.  Connect the appropriate pc comm port to the PDP-11 console terminal
  25. ; line.  If you have a 25-pin "D" connector on this line where it attaches
  26. ; to the VT-terminal, it can be removed and plugged directly into a pc comm
  27. ; 1 or 2 port (when that also has a 25-pin "D" connector).  The speed and
  28. ; etc (usually 9600, 8 data bits, no parity) of the PDP-11 port must be
  29. ; matched in the pc comm program, along with XOFF flow control, after which
  30. ; you should be able to talk to the PDP-11.
  31. ;
  32. ; 3.  Run PIP on the PDP-11, then give it a file name to create and tell
  33. ; it to take its input from the terminal.  Example:
  34. ;
  35. ; .PIP
  36. ; *KRT.HEX=TT:            ! or file name of your choice
  37. ; ^                ! PIP prints a ^ when it's ready for input
  38. ;
  39. ; You then use the comm program's ASCII transfer function to simply send
  40. ; the file across.  Note that you may have to insert delays between chars
  41. ; or lines (or both) to avoid overrunning the PDP-11, which will return a
  42. ; bell for each char thus lost.  When done, reconnect to the PDP-11 and
  43. ; type a control-Z to close the file:
  44. ;
  45. ; ^Z
  46. ; *
  47. ;
  48. ; When you've transfered all that you need, exit PIP with a control-C.
  49. ;
  50. ; 4.  This program (KRTHEX) needs to be assembled on the PDP-11 system.
  51. ;
  52. ; .macro krthex
  53. ; .link krthex
  54. ;
  55. ; This produces an executable program named KRTHEX.SAV which is then used
  56. ; to decode the .HEX files:
  57. ;
  58. ; .run krthex
  59. ; *KRT=KRT                ! here it's OUTPUT_file=INPUT_file
  60. ; *KRTTSX=KRTTSX
  61. ; *KRTMIN=KRTMIN            ! if using the floppies-only Kermit
  62. ; *^C                    ! type control-C to exit
  63. ;
  64. ; or
  65. ;
  66. ; .RUN KRTHEX KRT KRT            ! here it's INPUT_file OUTPUT_file
  67. ; .RUN KRTHEX KRTTSX KRTTSX
  68. ; .RUN KRTHEX KRTMIN KRTMIN        ! if using the floppies-only Kermit
  69. ;
  70. ; The default input file type is .HEX and .SAV is the output type default.
  71. ;
  72. ; 5.  After conversion it's a good idea to correct the creation dates:
  73. ;
  74. ; .RENAME/SETDAT:27:SEP:97 KRT*.SAV *    ! for the now current V03.63
  75. ; .RENAME/SETDAT:31:MAY:93 KRTMIN.SAV *    ! for KRTMIN V03.62-5_min
  76. ;
  77. ; You now have a runnable Kermit which may be used to get the rest of its
  78. ; own distribution.
  79.  
  80.  
  81.     .sbttl    Macros and misc constants
  82.  
  83.     .macro    mapch    reg        ; ascii to integer for HEX chars only
  84.     movb    map(reg),reg
  85.     .endm    mapch
  86.  
  87.     .macro    sob    reg    ,dst    ; subtract one and branch if <>
  88.     dec    reg
  89.     bne    dst
  90.     .endm    sob
  91.  
  92.     .MCALL    .CLOSE    ,.CSIGEN ,.EXIT    ,.GVAL    ,.PRINT    ,.READW    ,.WRITW
  93.     .ENABL    LC
  94.  
  95.     ERRBYT    = 52            ; emt error status byte
  96.     STATWD    = 366            ; indirect file status word
  97.         IFACTV    = 400        ; indirect file active bit
  98.  
  99.  
  100.     .sbttl    Data
  101.     .psect    $pdata    ,ro,d,lcl,rel,con
  102.  
  103. map:    .rept    48.            ; table returns integer value of ascii
  104.     .byte    377            ; HEX digit or -1 for any non-HEX char
  105.     .endr
  106.     .byte    0   ,1   ,2   ,3   ,4   ,5   ,6   ,7   ,8.  ,9.
  107.     .byte    377 ,377 ,377 ,377 ,377 ,377 ,377 ; skip past :;<=>?@
  108.     .byte    10. ,11. ,12. ,13. ,14. ,15. ; mapping "A" to "F" here..
  109.     .rept    256.-70.
  110.     .byte    377
  111.     .endr
  112.     .byte    0            ; .even
  113.  
  114. csierr:    .word    csier0    ,csier1    ,csier2    ,csier3    ,csier4
  115. .fatal:    .ascii    "?KRTHEX-F-"<200>
  116. alldone:.asciz    "%KRTHEX-I-Conversion completed"
  117. badch:    .asciz    "Non HEX data in input file"
  118. badchk:    .asciz    "Input file checksum error"
  119. csibad:    .ascii    "?CSIGEN-F-"<200>
  120. csier0:    .asciz    "Command line is invalid"
  121. csier1:    .asciz    "Device not found"
  122. csier2:    .asciz    "Protected file already exists"
  123. csier3:    .asciz    "Not enough room to open output file"
  124. csier4:    .asciz    "Input file not found"
  125. rderr:    .asciz    "Input file .READW error"
  126. version:.asciz    "KRTHEX V03.63  7-Sep-93"
  127. wrerr:    .asciz    "Output file .WRITW error"
  128.     .even
  129.  
  130.     .psect    $rwdata    ,rw,d,lcl,rel,con
  131. cmdbuf:    .blkb    82.            ; command line buffer
  132. defext:    .rad50    "HEXSAV      "        ; CSIGEN default extents
  133. handld:    .blkw    1000            ; handler loading done here
  134. inblk:    .word    0            ; input file current block number
  135. inbuff:    .blkw    400            ; the input file buffer
  136. inpnt:    .word    0            ; and pointer into it
  137. jobtyp:    .word    0            ; if <> params passed when pgm was run
  138. outblk:    .word    0            ; output file current block number
  139. outbuf:    .blkw    400            ; and same for the output file
  140. outpnt:    .word    0            ; and its pointer
  141. rtwork:    .blkw    10            ; read/write work area
  142.  
  143.  
  144.     .sbttl    Main program loop
  145.     .psect    $code    ,ro,i,lcl,rel,con
  146.  
  147. convert:.csigen    #handld    ,#defext ,#0 ,#cmdbuf ; get and process a command
  148.     bcc    10$            ; ok
  149.     movb    @#errbyt,r0        ; didn't work, get the error code
  150.     .print    #csibad            ; error message prefix
  151.     mov    #csierr     ,r1        ; mapping for CSIGEN errors
  152.     asl    r0            ; word addressing
  153.     add    r0    ,r1        ; get address of address of text
  154.     .print    (r1)            ; and dump message to the terminal
  155.     br    130$
  156.  
  157. 10$:    tstb    cmdbuf            ; was anything actually input?
  158.     bne    20$            ; ya
  159.     .print    #version        ; no, print version data
  160.     br    convert            ; and loop for input
  161.  
  162. 20$:    .gval    #rtwork    ,#statwd    ; indirect file status word
  163.     bit    #ifactv    ,r0        ; indirect file running this pgm?
  164.     beq    30$            ; no
  165.     inc    jobtype            ; ya, flag it for error handling
  166. 30$:    mov    #77777    ,inpnt        ; ensure first getc call gets a block
  167.     clr    inblk            ; input file current block number
  168.     clr    outblk            ; output file current block number
  169.     clr    outpnt            ; and its pointer
  170.  
  171. 40$:    mov    #40    ,r5        ; loop for the data record please
  172.     clr    r4            ; clear checksum if we use it
  173. 50$:    call    getc            ; get a character
  174.     bcs    100$            ; most likely all done
  175.     mov    r0    ,r3        ; save it
  176.     mapch    r3            ; check against table of HEX chars
  177.     bpl    60$            ; char was ok
  178.     .print    #.fatal            ; fatal error message prefix
  179.     .print    #badch            ; not ok
  180.     br    130$
  181.  
  182. 60$:    asl    r3            ; avoid
  183.     asl    r3            ; mul for
  184.     asl    r3            ; systems
  185.     asl    r3            ; w/o EIS
  186.     call    getc            ; get the next one please
  187.     bcs    90$            ; exit on I/O error please
  188.     mapch    r0            ; convert it to an integer
  189.     bpl    70$            ; it was ok
  190.     .print    #.fatal            ; fatal error message prefix
  191.     .print    #badch            ; say what went wrong
  192.     br    130$
  193.  
  194. 70$:    add    r3    ,r0        ; add it in and copy the byte
  195.     add    r0    ,r4        ; add into simpleminded checksum
  196.     call    putc            ; write it out
  197.     bcs    80$            ; I/O error on write
  198.     sob    r5    ,50$        ; finished with the read
  199.     call    getchk            ; read the checksum
  200.     cmp    r0    ,r4        ; do they match?
  201.     beq    40$            ; yes, read the next record now
  202.     .print    #.fatal            ; no, fatal error message prefix
  203.     .print    #badchk            ; print error and exit
  204.     br    130$
  205.  
  206. 80$:    .print    #.fatal            ; fatal error message prefix
  207.     .print    #wrerr            ; write error
  208.     br    130$
  209.  
  210. 90$:    .print    #.fatal            ; fatal error message prefix
  211.     .print    #rderr            ; read error
  212.     br    130$
  213.  
  214. 100$:    tst    outpnt            ; anything to dump out?
  215.     beq    120$            ; no (this should never happen..)
  216.     mov    outblk    ,r2        ; save current output block number
  217. 110$:    cmp    r2    ,outblk        ; did putc dump its buffer?
  218.     bne    120$            ; yes
  219.     clr    r0            ; no, dump a bunch of nulls out
  220.     call    putc            ; until putc flushes to disk
  221.     bcs    80$            ; I/O error on write
  222.     br    110$
  223.  
  224. 120$:    .close    #0            ; close the input file now
  225.     .close    #3            ; output also please
  226.     .print    #alldone        ; say conversion is completed
  227.     tst    jobtyp            ; params passed w/cmd to run program?
  228.     bne    130$            ; ya, so exit now
  229.     jmp    convert            ; no, back to where we started
  230.  
  231. 130$:    clr    r0            ; ensure any leftovers are cleaned up
  232.     .exit
  233.  
  234.  
  235.     .sbttl    Read the checksum
  236.  
  237. getchk:    clr    r3            ; init an accumulator
  238.     call    getc            ; skip past the ":"
  239.     bcs    20$            ; read error
  240.     call    getc            ; skip past the first byte
  241.     bcs    20$            ; read error
  242.     call    getc            ; skip the second byte too
  243.     bcs    20$            ; read error
  244.     mov    #4    ,r2        ; loop for the remaining four bytes
  245. 10$:    call    getc            ; get a char
  246.     bcs    20$            ; read error
  247.     asl    r3            ; avoid
  248.     asl    r3            ; mul for
  249.     asl    r3            ; systems
  250.     asl    r3            ; w/o EIS
  251.     mapch    r0            ; convert acsii to integer
  252.     add    r0    ,r3        ; add to accumulated total
  253.     sob    r2    ,10$        ; go do the next digit
  254. 20$:    mov    r3    ,r0        ; return result
  255.     return
  256.  
  257.  
  258.     .sbttl    Get the next character
  259.  
  260. getc:    cmp    inpnt    ,#1000        ; used up all previously read chars?
  261.     blo    10$            ; not yet
  262.     clr    inpnt            ; ya, reset the buffer read pointer
  263.     .readw    #rtwork    ,#3 ,#inbuff ,#400 ,inblk ; read in another block
  264.     bcs    20$            ; hit the end of file
  265.     inc    inblk            ; next time read the next block please
  266. 10$:    mov    inpnt    ,r0        ; get the current buffer offset
  267.     inc    inpnt            ; +1 for the char about to be returned
  268.     movb    inbuff(r0) ,r0        ; and return the character
  269.     bic    #^c<177>,r0        ; ensure it's 7-bit data
  270.     cmpb    r0    ,#15        ; a CR or less?  if not carry cleared
  271.     blos    getc            ; yes, skip it, go get the next char
  272. 20$:    return                ; exit with error status in carry bit
  273.  
  274.  
  275.     .sbttl    Put the next character
  276.  
  277. putc:    cmp    outpnt    ,#1000        ; is the output buffer full yet?
  278.     blo    10$            ; no
  279.     clr    outpnt            ; ya, reset its output pointer
  280.     mov    r0    ,-(sp)        ; save the character being put
  281.     .writw    #rtwork    ,#0 ,#outbuff ,#400 ,outblk ; dump the buffer to disk
  282.     mov    (sp)+    ,r0        ; restore that character please
  283.     bcs    20$            ; hit end of file, else carry is clear
  284.     inc    outblk            ; next time write the next block
  285. 10$:    mov    outpnt    ,r1        ; get the current buffer offset
  286.     inc    outpnt            ; +1 for char about to be stored
  287.     movb    r0    ,outbuff(r1)    ; and store the character
  288.     clc                ; ..must do due to branch at top
  289. 20$:    return                ; exit with error status in carry bit
  290.  
  291.     .end    convert
  292.