;---------------------------------------
; MV (MOVE) a direntry to another subdir
;
;Suntax: mv (file) [newpath]
;V22 written 24/1/1991
;---------------------------------------

indr1    = $02
dircurr  = $09
nountick = $59
nountot  = $6c
buffer   = $0840
calcdir  = $091e
chkexist = $0924
dirread  = $0927
scandir2 = $1009
nounnum  = $1018
nounstart = $101b
nounlen  = $1021

;---------------------------------------
         *= $c000

move     jsr nounnum
         jsr scandir2
         bcs error1       ;Not such file

         sta filesnum
         lda dircurr
         sta dirtmp

movenoun inc nountick
         lda nountick
         cmp nountot
         beq moveit

         jsr nounlen
         tay
         cmp #3
         bcs movedir
         jsr nounstart
         lda buffer,x
         cmp #"/"
         bne moveslash
         cpy #1
         bne movedir
         lda #0
         jmp move3

moveslash cmp #"."
         bne movedir
         cmp buffer+1,x
         bne movedir

         ldy #0
         lda dircurr
         jsr dirread

move3    sta dircurr
         jmp movenoun


movedir  jsr nounnum
         jsr scandir2
         bcs error2      ;No dir
         sta dircurr
         jmp movenoun


moveit   lda filesnum
         jsr calcdir
         lda dircurr
         cmp dirtmp
         beq error3      ;Twilight Zone
         ldy #0
         sta (indr1),y
         tya
         clc

quit     ldx dirtmp
         stx dircurr
         rts


error1   lda #11
         .byte $2c
error2   lda #18
         .byte $2c
error3   lda #30
         sec
         bne quit


;11 No such file
;18 No such directory
;23 File exists
;30 Twilight Zone

filesnum = *
dirtmp   = *+1


