cseg      segment
vidit     macro    string,stringsz   ;display
          mov      dx,offset string  ;string on
          mov      cx,stringsz       ;stdout
          call     display
          endm


main      proc     far
          assume   cs:cseg,ds:cseg,es:cseg
          org      100H


start:   vidit     slugline,slugsz
         vidit     from,fromsz
         mov       dx,offset namone
         mov       ah,0AH
         int       21H
         vidit     crlf,crlfsz
         vidit     to,tosz
         mov       dx,offset namtwo
         mov       ah,0AH
         int       21H
         vidit     crlf,crlfsz
;put zero in both buffers
;makes it an ASCIIZ string
         mov       bl,namone+1
         mov       bh,0
         mov       [namone+bx+2],0
         mov       bl,namtwo+1
         mov       bh,0
         mov       [namtwo+bx+2],0

;first, some error handling.
;check and see if a drive was
;accessed.


         lea       di,namone+2
         xor       ch,ch
         mov       cl,namone+1
         mov       al,':'
         repne     scasb
         je        error1

;now check to see if file actually
;exists.
         mov       dx,offset namone+2
         mov       cx,00 ;normal r/w attribute
         mov       ah,4EH
         int       21H
         jc        error2

;now, point DS:DX to namone
;ES:DI to namtwo and
;execute function 56H of 21H

at_last:
         mov       dx,offset namone+2
         mov       di,offset namtwo+2
         mov       ah,56H
         int       21H
         jc        error2
         jmp       all_ok

all_ok:
;now, let the user know what's going
;on, by printing out the action of
;the program.
         vidit     crlf,crlfsz
         vidit     workline,worksz
         mov       dx,offset namone+2
         xor       cx,cx
         mov       cl,[namone+1]
         call      display
         vidit     word1,word1sz
         mov       dx,offset namtwo+2
         xor       cx,cx
         mov       cl,[namtwo+1]
         call      display
         jmp       exit


error1:  vidit     crlf,crlfsz
         vidit     errmes1,errmes1sz
         jmp       exit

error2:  vidit     crlf,crlfsz
         vidit     errmes2,errmes2sz
         jmp       exit

exit:    mov       ah,4CH   ;DOS 2.x version
         int       21H      ;of int 20H


slugline db        'CHANGE, Copyright (c) '
         db        'Ron Gans, 1985',0DH,0AH
slugsz   equ       $-slugline
workline db        'CHANGEing . . . '
worksz   equ       $-workline
word1    db        ' . . . to . . . '
word1sz  equ       $-word1
crlf     db        0DH,0AH
crlfsz   equ       $-crlf
namone   db        63
         db        ?
         db        63 dup(?)

namtwo   db        63
         db        ?
         db        63 dup(?)

from     db        'Change from: '
fromsz   equ       $-from
to       db        'Change to: '
tosz     equ       $-to

errmes1  db        'Do not use drive prefix [x:]. '
         db        'Note: Files must be on same drive.'
errmes1sz equ      $-errmes1
errmes2  db        'CHANGE aborted. File or path not found.'
errmes2sz equ      $-errmes2


main     endp

display  proc      near
;this proc displays what ds:dx points
;to. Before the proc is called, DX must
;be loaded with the offset of the string
;to be displayed. CX must be loaded with the
;SZ of the string
         mov      ah,40h   ;write to device
         mov      bx,0001  ;handle of stdout
         int      21H
         ret
display  endp


cseg     ends
         end       start

