home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / network / fix36.asm < prev    next >
Assembly Source File  |  1994-03-04  |  4KB  |  141 lines

  1. Date:    Fri, 19 Feb 88 01:13:04 GMT
  2. From:    granroth%iowasp.span@Sds.Sdsc.Edu (Larry Granroth 319/335-1960)
  3. Subject: tenex conversion for the pc
  4. To:      info-ibmpc@walker-emh.arpa
  5.  
  6. The following code may come in handy for people who are having difficulty
  7. FTPing binary files from SIMTEL20 or other TOPS-20 systems to MS-DOS PC's.
  8. The program FIX36 was developed on an XT clone with MASM 4.0.  It reads
  9. 36-bit groups from standard input and re-packs the data into 32-bit
  10. groups to standard output, removing the 4 extraneous zero bits from each
  11. group.
  12.  
  13. Larry Granroth
  14. GRANROTH%IOWASP.SPAN@SDS  (soon to be GRANROTH@IOWASP.PHYSICS.UIOWA.EDU)
  15.  
  16.     page    54,132
  17.     title    FIX36:  fix image ftp's from tops20 systems
  18. ;----------------------------------------------------------------------
  19. ;
  20. ;    FIX36 version 02-18-88  MASM 4.0
  21. ;    Copyright (c) 1988 by Larry Granroth
  22. ;    This code may be freely distributed for non-commercial purposes
  23. ;    only.  Modifications to the code may be made as long as they
  24. ;    are clearly documented.
  25. ;    
  26. ;    When doing an image (or binary) type FTP transfer from a TOPS-20
  27. ;    system, the resulting file contains 32-bit data packed in 36-bit
  28. ;    groups (each with 4 trailing zero bits).
  29. ;    This program reads such a file from standard input and
  30. ;    repacks the data, removing the extraneous bits, to standard
  31. ;    output.  In certain cases, for example VAX/VMS systems running
  32. ;    CMU TCP/IP software, the creation of an image file will result
  33. ;    in the file being padded out to an integral number of 512-byte
  34. ;    blocks.  If this file is moved to a PC and processed with FIX36,
  35. ;    it will still have the extra trailing zeros.
  36. ;    Note that, if your FTP implementation supports the feature,
  37. ;    the correct transfer type is "TYPE L 8", in which case this
  38. ;    program would not be needed.
  39. ;
  40. ;    usage:
  41. ;    C> fix36 <infile.bin >outfile.bin
  42. ;
  43. ;----------------------------------------------------------------------
  44.  
  45. cseg    segment    para public 'CODE'
  46.     assume cs:cseg,ds:cseg,es:cseg,ss:cseg
  47.  
  48.     org    100h
  49.  
  50. fix36    proc    near
  51.  
  52. read:    mov    dx, offset buffer    ; ds:dx points to buffer
  53.     xor    bx,bx            ; stdin file handle 0
  54.     mov    cx,4608            ; number of bytes to read (512*9)
  55.     mov    ah,3fh            ; read function
  56.     int    21h            ; dos call
  57.     jc    abort
  58.     or    ax,ax            ; test for zero
  59.     jz    eof
  60.     mov    cx,ax            ; save number of bytes read
  61.  
  62.     mov    si,dx            ; ds:si points to first input byte
  63.     mov    di,dx            ; ds:di points to first output byte
  64.     cld
  65.  
  66. first:    movs    word ptr [di],word ptr [si] ; just move 4 bytes
  67.     movs    word ptr [di],word ptr [si]
  68.  
  69. second:    lods    word ptr [si]        ; load next 2 bytes
  70.     rol    ax,1
  71.     rol    ax,1
  72.     rol    ax,1
  73.     rol    ax,1            ; rotate 4 bits left
  74.     mov    dx,ax            ; save in dx
  75.  
  76. third:    lods    word ptr [si]        ; load next 2 bytes
  77.     mov    bx,ax            ; save in bx
  78.     mov    ax,dx            ; work on previous 2 bytes
  79.     mov    dx,bx            ; save another copy
  80.     shr    bl,1
  81.     shr    bl,1
  82.     shr    bl,1            ; shift out lower nibble
  83.     shr    bl,1            ;  and position higher nibble
  84.     or    ah,bl            ; put higher nibble where it belongs
  85.     stos    word ptr [di]        ; restore first corrected word
  86.  
  87. fourth:    lods    byte ptr [si]        ; get 9th byte in cycle
  88.     and    dl,0fh            ; mask out higher nibble
  89.     or    dl,al            ; put in remaining nibble
  90.     mov    ax,dx            ; move back to accumulator
  91.     rol    ax,1
  92.     rol    ax,1
  93.     rol    ax,1
  94.     rol    ax,1            ; rotate left one nibble
  95.     stos    word ptr [di]        ; restore second corrected word
  96.  
  97.     sub    cx,9            ; work with groups of 9 bytes
  98.     jg    first            ; loop if more
  99.  
  100.     jz    write
  101.  
  102.     cmp    cx,-4            ; this adjusts for a total
  103.     jl    adjust            ;  byte count which is not
  104.     sub    cx,1            ;  a multiple of 9
  105. adjust: add    di,cx
  106.  
  107. write:    mov    dx,offset buffer    ; get buffer address
  108.     mov    cx,di            ; output index
  109.     sub    cx,dx            ; number of re-formatted bytes
  110.     mov    bx,1            ; stdout file handle 1
  111.     mov    ah,40h            ; write function
  112.     int    21h            ; dos call
  113.     jc    abort            ; abort on error
  114.     jmp    read            ; read another buffer
  115.  
  116. eof:    mov    bx,1            ; stdout file handle 1
  117.     mov    ah,3eh            ; close function
  118.     int    21h
  119.     jc    abort
  120.     xor    al,al            ; successful exit code 0
  121.     jmp    exit
  122.  
  123. abort:    mov    si,ax            ; save the error code
  124.     mov    bx,2            ; stderr file handle 2
  125.     mov    cx,16            ; 16 characters in error message
  126.     mov    dx,offset errmsg    ; ds:dx points to errmsg
  127.     mov    ah,40h            ; write function
  128.     int    21h            ; dos call
  129.     mov    ax,si            ; original error code in al
  130.  
  131. exit:    mov    ah,4ch            ; return to dos
  132.     int    21h
  133.  
  134. fix36    endp
  135.  
  136. errmsg    db    13,10,'Fix36 Error',7,13,10
  137. buffer    db    4608 dup (?)
  138.  
  139. cseg    ends
  140.     end    fix36
  141.