; ---------------------------------------- ;
; MOVE.ASM                                 ;
;                                          ;
; Version 1.0                              ;
;                                          ;
; IC v2.0+ Installable Command             ;
;                                          ;
; MOVE filespecs from one area to another. ;
;                                          ;
; Copyright (C) 1992, Geoff Friesen B.Sc.  ;
; All rights reserved.                     ;
;                                          ;
; Developed with: Borland TASM 2.5         ;
; ---------------------------------------- ;

_TEXT           SEGMENT BYTE PUBLIC 'CODE'
		ASSUME  cs:_TEXT, ds:_TEXT, es:_TEXT, ss:_TEXT
		ORG     100h

CR              EQU     13
LF              EQU     10
TAB		EQU	9

CLINE		EQU	10ah
HEXW		EQU	10ch
STDINIT		EQU	10eh

_move:
		lea     dx, msg
		mov     ah, 9
		int     21h
		int     20h

msg             DB      "NONCOM$"

code_entry      DW      _code
help_entry      DW      _help
byline_entry    DW      _byline
setup_entry     DW      _setup
cleanup_entry   DW      _cleanup

_dpl		STRUC
 _ax		DW	?
 _bx		DW	?
 _cx		DW	?
 _dx		DW	?
 _si		DW	?
 _di		DW	?
 _ds		DW	?
 _es		DW	?
 _reserved	DW	?
 _computerid	DW	?
 _processid	DW	?
_dpl		ENDS

parm		_dpl	<5600h, 0, 0, OFFSET _source, 0, OFFSET _target, \
			 0, 0, 0, 0, 0>

_source		DB	128 DUP (?)
_target		DB	128 DUP (?)

_errmsg1	DB	CR, LF
		DB	"move: bad command line"
		DB	CR, LF
		DB	'$'

_errmsg2	DB	CR, LF
		DB	"move: invalid filespec"
		DB	CR, LF
		DB	'$'

_errmsg3	DB	CR, LF
		DB	"move: source & target must be on same drive"
		DB	CR, LF
		DB	'$'

_errmsg4	DB	CR, LF
		DB	"move: unable to move"
		DB	CR, LF
		DB	'$'

_okmsg		DB	CR, LF
		DB	"move: move successful"
		DB	CR, LF
		DB	'$'

_code           PROC    NEAR
		call	cs:[STDINIT]	; Standard initialization.
		push	cs
		pop	es

		lea	dx, _errmsg1	; Assume error.

		call	_copy		; Copy command line filespecs.
		jc	_code1		; Branch on error.

		mov	ah, 60h		; Canonicalize source filespec.
		lea	si, _source
		lea	di, _source
		int	21h

		lea	dx, _errmsg2	; Assume error.
		jc	_code1		; Branch on error.

		mov	ah, 60h		; Canonicalize target filespec.
		lea	si, _target
		lea	di, _target
		int	21h

		lea	dx, _errmsg2	; Assume error.
		jc	_code1		; Branch on error.

		mov	al, ds:[_source]
		mov	ah, ds:[_target]

		lea	dx, _errmsg3	; Assume error.
		cmp	al, ah		; Same source & target drives?
		jnz	_code1		; No, error.

		lea	si, parm	; Finish filling in parm table.
		mov	[si]._ds, cs
		mov	[si]._es, cs

		mov	ax, 5d00h	; Generate indirect rename func.
		lea	dx, parm
		int	21h

		lea	dx, _okmsg	; Assume ok.
		jnc	_code1		; Branch on ok.

		cmp	ax, 12h		; OS/2 returns this in DOS BOX.
		jz	_code1		; Branch if ok (even if carry set).

		lea	dx, _errmsg4	; Must be error.
_code1:
		mov	ah, 9		; Display message.
		int	21h

		ret
_code           ENDP

; ------------------------------------------------------------- ;
; COPY: Copy command line to source and target buffers.         ;
;                                                               ;
; Entry: DS:SI - address of first nonwhitespace on command-line ;
;                                                               ;
; Exit: source and target contain filespecs                     ;
;       Carry flag set if error.                                ;
;                                                               ;
; Registers AX, SI, and DI modified                             ;
; ------------------------------------------------------------- ;

_copy		PROC	NEAR
		lea	di, _source	; Begin with source buffer.
_copy1:
		lodsb			; Get command line character.

		cmp	al, ' '		; Exit on space.
		jz	_copy2

		cmp	al, TAB		; Exit on TAB.
		jz	_copy2

		cmp	al, CR		; Error if CR (no arguments).
		jz	_copy6

		stosb			; Copy character.
		jmp	SHORT _copy1
_copy2:
		mov	al, 0		; Delimit buffer with NULL.
		stosb

		lea	di, _target	; Now processing target.
_copy3:
		lodsb			; Get command line character.

		cmp	al, ' '		; Skip spaces.
		jz	_copy3

		cmp	al, TAB		; Skip tabs.
		jz	_copy3

		cmp	al, CR		; Error if CR (no second arg).
		jz	_copy6

		stosb			; Copy character.
_copy4:
		lodsb			; Get command line character.

		cmp	al, ' '		; Exit on space.
		jz	_copy5

		cmp	al, TAB		; Exit on tab.
		jz	_copy5

		cmp	al, CR		; Exit on CR.
		jz	_copy5

		stosb			; Copy character.
		jmp	SHORT _copy4
_copy5:
		mov	al, 0		; Delimit buffer with NULL.
		stosb

		clc			; Signal success.
		ret
_copy6:
		stc			; Signal failure.
		ret
_copy		ENDP

_help           DB      CR, LF
		DB      "MOVE: Move files from one area to another"
		DB      CR, LF
		DB	CR, LF
		DB	"Syntax: MOVE oldfilespec newfilespec"
		DB	CR, LF
		DB	CR, LF
		DB	"The MOVE command offers the ability to move files"
		DB	CR, LF
		DB	"from one area to another on the same drive.  This"
		DB	CR, LF
		DB	"is accomplished through a variation of the RENAME"
		DB	CR, LF
		DB	"facility.  Either a single file or multiple files"
		DB	CR, LF
		DB	"via wildcards may be specified as oldfilespec.  A"
		DB	CR, LF
		DB	"complete file specification must be specified as"
		DB	CR, LF
		DB	"newfilespec.  The following examples should help."
		DB	CR, LF
		DB	CR, LF
		DB	"move x.doc \dos\x.doc"
		DB	CR, LF
		DB	"move \dos\*.* \temp\dos\*.*"
		DB	CR, LF
		DB	"move x.doc a.doc (similar to REN or RENAME)"
		DB	CR, LF
		DB	CR, LF
		DB	"If the root directory is specified as newfilespec"
		DB	CR, LF
		DB	"then the target filename need not be specified (a"
		DB	CR, LF
		DB	"quirk).  Files cannot be moved to devices."
		DB	CR, LF
		DB	'$'

_byline         DB      "MOVE     - move files from one area to another"
		DB      CR, LF
		DB      '$'

smsg		DB	CR, LF
		DB	"move: setting up"
		DB	CR, LF
		DB	'$'

_setup          PROC    NEAR
		lea	dx, smsg
		mov	ah, 9
		int	21h

		ret
_setup          ENDP

cmsg		DB	CR, LF
		DB	"move: cleaning up"
		DB	CR, LF
		DB	'$'

_cleanup        PROC    NEAR
		lea	dx, cmsg
		mov	ah, 9
		int	21h

		ret
_cleanup        ENDP

_TEXT           ENDS
		END     _move