home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11hex.mac < prev    next >
Text File  |  2020-01-01  |  4KB  |  175 lines

  1.     .title    k11hex    create k11prt.sav and/or k11rt4.sav from hex file
  2.     .ident    /2.23/
  3.  
  4.  
  5. ;    25-Oct-84  11:14:41  Brian Nelson
  6. ;
  7. ;    Usage:    run k11hex
  8. ;        *k11prt=k11prt
  9. ; or        *k11rt4=k11rt4
  10.  
  11.  
  12.  
  13.  
  14.     .mcall    .close    ,.csigen,.exit    ,.readw    ,.writw    ,.print
  15.  
  16.     .psect
  17.  
  18.     .macro    sob    reg    ,dst
  19.     dec    reg
  20.     bne    dst
  21.     .endm    sob
  22.  
  23.     .macro    mapch    ch
  24.     movb    map(ch)    ,ch
  25.     .endm    mapch
  26.  
  27. map:    .rept    48.
  28.     .byte    377
  29.     .endr
  30.     .byte    0,1,2,3,4,5,6,7,8.,9.
  31.     .byte    377,377,377,377,377,377,377
  32.     .byte    10.,11.,12.,13.,14.,15.
  33.     .rept    256.-70.
  34.     .byte    377
  35.     .endr
  36.  
  37.     .even
  38. rtwork:    .blkw    10
  39. inblk:    .word    0
  40. outblk:    .word    0
  41. inpnt:    .word    0
  42. outpnt:    .word    0
  43. inbuff:    .blkw    400
  44. outbuf:    .blkw    400
  45.  
  46.     .enabl    lc
  47. wrerr:    .asciz    /Write error on device/
  48. rderr:    .asciz    /Read  error from file/
  49. badch:    .asciz    /Non HEX character read from input/
  50. badchk:    .asciz    /Checksum error/
  51. alldone:.asciz    /All done/
  52. csibad:    .asciz    /Could not open the files on the command line/
  53.     .even
  54. defext:    .rad50    /HEX/
  55.     .rad50    /SAVSAVSAV/
  56.  
  57.  
  58.  
  59.  
  60. convert:.csigen    #handld,#defext,#0    ; get a command
  61.     bcc    5$            ; ok
  62.     .print    #csibad            ; no good
  63.     .exit
  64.  
  65. 5$:    mov    #77777    ,inpnt        ; ensure fist getc call gets a block
  66. 10$:    mov    #40    ,r5        ; loop for the data record please
  67.     clr    r4            ; clear checksum if we use it
  68. 20$:    call    getc            ; get a character
  69.     bcs    60$            ; most likely all done
  70.     mov    r0    ,r3        ; save it
  71.     mapch    r3
  72.     bpl    30$            ; char was ok
  73.     .print    #badch            ; not ok
  74. 30$:    asl    r3            ; avoid mul for systems w/o EIS
  75.     asl    r3            ; avoid mul for systems w/o EIS
  76.     asl    r3            ; avoid mul for systems w/o EIS
  77.     asl    r3            ; avoid mul for systems w/o EIS
  78.     call    getc            ; get the next one please
  79.     bcs    80$            ; exit on i/o error please
  80.     mapch    r0            ; convert it
  81.     bpl    40$            ; it was ok
  82.     .print    #badch            ; error
  83. 40$:    add    r3    ,r0        ; add it in and copy the byte
  84.     add    r0    ,r4        ; add into simpleminded checksum
  85.     call    putc            ; write it out
  86.     bcs    70$            ; i/o error on write
  87.     sob    r5    ,20$        ; finished with the read
  88.     call    getchk            ; read the checksum
  89.     cmp    r0    ,r4        ; do they match ?
  90.     beq    50$            ; yes
  91.     .print    #badchk            ; no, print error and exit
  92. 50$:    br    10$            ; read the next record now
  93.  
  94. 60$:    call    close            ; close up and exit
  95.     br    100$            ; bye
  96.  
  97. 70$:    .print    #wrerr            ; write error
  98.     br    100$            ; exit
  99. 80$:    .print    #rderr            ; a read error
  100.     br    100$            ;
  101.  
  102. 100$:    .print    #alldone
  103.     .exit
  104.  
  105.  
  106. getchk:    clr    r3
  107.     call    getc
  108.     bcs    100$
  109.     call    getc
  110.     call    getc
  111.     mov    #4    ,r2
  112. 10$:    call    getc
  113.     asl    r3            ; avoid mul for systems w/o EIS
  114.     asl    r3            ; avoid mul for systems w/o EIS
  115.     asl    r3            ; avoid mul for systems w/o EIS
  116.     asl    r3            ; avoid mul for systems w/o EIS
  117.     mapch    r0
  118.     add    r0    ,r3
  119.     sob    r2    ,10$
  120. 100$:    mov    r3    ,r0
  121.     return
  122.  
  123.  
  124.  
  125. getc:    call    .getc            ; get the next character
  126.     bcs    100$            ; oops
  127.     cmpb    r0    ,#15        ; carriage return or less?
  128.     blos    getc            ; yes, get the next character then
  129.     clc                ; no, return it
  130. 100$:    return                ; exit with c bit error code
  131.  
  132. .getc:    cmp    inpnt    ,#1000
  133.     blo    10$
  134.     clr    inpnt            ; clear the buffer offset also
  135.     .readw    #rtwork,#3,#inbuff,#400,inblk
  136.     bcs    100$            ; end of file
  137.     inc    inblk            ; next time the next block please
  138. 10$:    mov    inpnt    ,r0        ; get the current buffer offset
  139.     inc    inpnt            ; + 1
  140.     movb    inbuff(r0),r0        ; and return the character
  141.     clc                ; success
  142. 100$:    return                ; exit with success in 'c' bit
  143.  
  144.  
  145. putc:    cmp    outpnt    ,#1000        ; room for more output data
  146.     blo    10$
  147.     clr    outpnt            ; clear the buffer offset also
  148.     mov    r0    ,-(sp)        ; save the character being put
  149.     .writw    #rtwork,#0,#outbuff,#400,outblk
  150.     mov    (sp)+    ,r0        ; restore that character please
  151.     bcs    100$            ; end of file
  152.     inc    outblk            ; next time the next block please
  153. 10$:    mov    outpnt    ,r1        ; get the current buffer offset
  154.     inc    outpnt            ; + 1
  155.     movb    r0    ,outbuff(r1)    ; and return the character
  156.     clc                ; success
  157. 100$:    return                ; exit with success in 'c' bit
  158.  
  159.  
  160. close:    tst    outpnt            ; anything to dump out
  161.     beq    20$            ; no, should not be
  162.     mov    outblk    ,r2        ; save current output block #
  163. 10$:    cmp    r2    ,outblk        ; did it dump it's buffer?
  164.     bne    20$            ; yes
  165.     clr    r0            ; yes, dump a bunch of nulls out
  166.     call    putc            ; until putc clears the pointer
  167.     br    10$
  168. 20$:    .close    #0            ; close the two file now
  169.     .close    #3            ; output also please
  170.     return
  171.  
  172. handld:    .blkw    500
  173.  
  174.     .end    convert
  175.