home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pckermit / pckfix.asm < prev    next >
Assembly Source File  |  2020-01-01  |  5KB  |  213 lines

  1. ; PCKFIX.ASM -- 
  2. ; Input file: KERMIT.EXE
  3. ; Output file: KERMIT.FIX
  4. ; The new file is a printable version of the executable file.  Each byte
  5. ; in the EXE file is converted to two bytes in the FIX file: a constant
  6. ; of "0" (30H) is added to each nibble.  
  7. ;
  8. ; Daphne Tzoar, December 1983
  9. ; Columbia University Center for Computing Activities
  10.  
  11. DOS    EQU    21H
  12.  
  13. STACK    SEGMENT    PARA STACK 'STACK'
  14.     DW     100 DUP (0)
  15. STK    EQU    THIS WORD
  16. STACK     ENDS    
  17.  
  18. DATAS    SEGMENT    PARA PUBLIC 'DATAS'
  19. buff    db    80H DUP(0)        ; Use our own DTA.
  20. bufone    db    80H DUP(0)        ; Data read from EXE file.
  21. buftwo    db    80H DUP(0)        ; Data to write out to FIX file.
  22. fcbold    db    25H DUP(0)        ; For the EXE file. 
  23. fcbnew    db    25H DUP(0)        ; File the FIX file.
  24. oldstk    dw    ?
  25. kold    db    'KERMIT  EXE$'
  26. knew    db    'KERMIT  FIX$'
  27. chrcnt    db    0            ; Number of chars left in BUFONE.
  28. datcnt    db    0            ; Number of chars in BUFTWO.
  29. eoflag    db    0            ; Remember when we hit the EOF. 
  30. crflg    db    0            ; Flag when it's time to add a CRLF.
  31. cnt    db    0            ; Determine when to add a CRLF.
  32. DATAS    ENDS
  33.  
  34. MAIN    SEGMENT    PARA PUBLIC 'MAIN'
  35. START    PROC    FAR
  36.     ASSUME CS:MAIN,DS:DATAS,SS:STACK,ES:NOTHING
  37.  
  38.     push ds                ; Initialization
  39.     sub ax,ax
  40.     push ax
  41.  
  42.     mov ax,datas            ; More of the same.......
  43.     mov ds,ax
  44.     sub ax,ax
  45.  
  46.     mov oldstk,sp
  47.  
  48.     mov ah,1AH            ; Use my own DTA
  49.     mov dx,offset buff
  50.     int dos
  51.     call one            ; Do the important stuff.
  52.     mov sp,oldstk
  53.     ret                ; Done.
  54. START     ENDP
  55.     
  56. ONE    PROC    NEAR
  57.     mov bx,offset fcbold
  58.     mov ah,0
  59.     mov [bx],ah            ; Use default drive.
  60.     inc bx
  61.     mov di,offset kold        ; Get name of original file.
  62. kerm3:    mov ah,[di]
  63.     cmp ah,'$'            ; Got all the data?
  64.     je kerm4
  65.     mov [bx],ah
  66.     inc di
  67.     inc bx
  68.     jmp kerm3
  69. kerm4:  mov bx,offset fcbnew        ; Put name of new file here.
  70.     mov ah,0
  71.     mov [bx],ah
  72.     inc bx
  73.     mov di,offset knew
  74. kerm5:    mov ah,[di]
  75.     cmp ah,'$'
  76.     je kerm6
  77.     mov [bx],ah
  78.     inc di
  79.     inc bx
  80.     jmp kerm5
  81.  
  82. kerm6:    mov ax,0
  83.     mov bx,offset fcbold+0CH
  84.     mov [bx],ax            ; Zero current block number.
  85.     mov bx,offset fcbold+0EH
  86.     mov [bx],ax            ; Lrecl.
  87.     mov bx,offset fcbold+20H
  88.     mov [bx],ah            ; Current record (of block).
  89.     inc bx
  90.     mov [bx],ax            ; Current record (of file).
  91.     mov bx,offset fcbold+23H
  92.     mov [bx],ax
  93.     mov ah,0FH            ; Open file.
  94.     mov dx,offset fcbold
  95.     int dos
  96.  
  97.     mov ax,0
  98.     mov bx,offset fcbnew+0CH
  99.     mov [bx],ax            ; Zero current block number.
  100.     mov bx,offset fcbnew+0EH
  101.     mov [bx],ax            ; Lrecl.
  102.     mov bx,offset fcbnew+20H
  103.     mov [bx],ah            ; Current record (of block).
  104.     inc bx
  105.     mov [bx],ax            ; Current record (of file).
  106.     mov bx,offset fcbnew+23H
  107.     mov [bx],ax
  108.     mov ah,16H            ; Create file.
  109.     mov dx,offset fcbnew
  110.     int dos
  111.     mov eoflag,0            ; Not end-of-file yet.
  112.     mov datcnt,0            ; Chars in write-out buffer.
  113.     mov chrcnt,0            ; Chars in read-to buffer.
  114.     mov crflg,0
  115.     mov cnt,0
  116.     mov bx,offset bufone
  117.     mov di,offset buftwo
  118.  
  119. kerm1:    cmp chrcnt,0H            ; Any chars left in buffer?
  120.     jne kerm0            ; Yes, continue.
  121.     call inbuf            ; Else get a buffer-full.
  122.       jmp kerm9            ; Hit the EOF.
  123.     mov ax,ds
  124.     mov es,ax            ; Move for Dest uses ES register.
  125.     mov si,offset buff
  126.     push di
  127.     mov di,offset bufone        ; Move read-in data to bufone.
  128.     mov cx,80H
  129.     rep movs es:bufone,buff
  130.     pop di
  131.  
  132.     mov bx,offset bufone        ; Where the chars are.
  133.     mov chrcnt,80H            ; Number of chars.
  134. kerm0:    cmp datcnt,80H            ; Time to write out the buffer?
  135.     je kerm2            ; Yup.
  136.     dec chrcnt
  137.     mov ah,[bx]            ; Get a char.
  138.     mov ch,ah            ; Save here.
  139.     and ah,0F0H            ; Get high nibble.
  140.     and ch,0FH            ; Lower nibble.
  141.     mov cl,4
  142.     shr ax,cl
  143.     add ah,'0'            ; Make printable.
  144.     mov [di],ah
  145.     inc datcnt
  146.     inc di
  147.     add ch,'0'
  148.     mov [di],ch
  149.     inc datcnt
  150.     inc di
  151.     inc bx
  152.     add cnt,2
  153.     cmp cnt,3EH            ; Time to add CRLF?
  154.     jne kerm1            ; Nope, keep going.
  155.     mov cnt,0            ; Reset counter.
  156.     cmp datcnt,80H            ; Have room for it?
  157.     jne kerm8            ; Yup, we do.
  158.     mov crflg,0FFH            ; No - remember add it later.
  159.     jmp kerm2
  160.  
  161. kerm8:    mov crflg,0
  162.     mov ax,0A0DH            ; Add the CRLF.
  163.     mov [di],ax
  164.     inc di
  165.     inc di
  166.     add datcnt,2
  167.     jmp kerm1
  168.  
  169. kerm2:     mov ax,ds
  170.     mov es,ax            ; Move for Dest uses ES register.
  171.     mov si,offset buftwo
  172.     mov di,offset buff
  173.     mov cx,80H
  174.     rep movs es:buff,buftwo        ; Must use BUFF for r/w to file.
  175.  
  176.     mov ah,15H            ; Write out to file two.
  177.     mov dx,offset fcbnew
  178.     int dos
  179.     mov datcnt,0
  180.     mov di,offset buftwo        ; Start at beginning of buffer.
  181.     cmp crflg,0FFH            ; Had our buffer filled prior to CRLF?
  182.     je kerm8            ; Yup.
  183.     jmp kerm1            ; Get new buffer-full.
  184.  
  185. kerm9:    mov ah,10H            ; Close files.    
  186.     mov dx,offset fcbold
  187.     int dos
  188.     mov dx,offset fcbnew
  189.     int dos
  190.     ret
  191.  
  192. inbuf:  cmp eoflag,0            ; End of file?
  193.     je inbuf0            ; Nope.
  194.     ret
  195. inbuf0:    mov dx,offset fcbold
  196.     mov ah,14H            ; Read from file.
  197.     int dos
  198.     cmp al,0
  199.     je inbuf2
  200.     mov eoflag,0FFH
  201. inbuf2: jmp rskp
  202. ONE     ENDP
  203.  
  204. RSKP    PROC  NEAR
  205.     pop bp
  206.     add bp,3
  207.     push bp
  208.     ret
  209. RSKP    ENDP
  210.  
  211. MAIN    ENDS
  212.     END     START
  213.