home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / DISKD.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  3KB  |  137 lines

  1.     page    66,132
  2. ;******************************** DISKD.ASM  *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  DISK   )
  14. CHANGE_PATH - switch to new directory, but save current path first
  15. ;
  16. ; inputs:  es:bx - points to new path
  17. ; outputs: old_path has origional path
  18. ;        carry set if dos error
  19. ;* * * * * * * * * * * * * *
  20. 
  21. old_path    label    byte
  22. old_drive    db    0
  23.         db    ':'
  24. old_sep        db    '\'
  25.         db    40 dup (0)
  26.  
  27. new_path    label    byte
  28.         db    40 dup (0)
  29. ;--------------------------------
  30.     public    change_path        
  31. CHANGE_PATH    PROC    FAR
  32.     push    ds
  33.     mov    ah,19h
  34.     int    21h        ;get current drive# in -al-
  35.         add     al,'A'
  36.     mov    cs:old_drive,al
  37. ;
  38. ; save current path
  39. ;    
  40.     mov    ax,cs
  41.     mov    ds,ax
  42.     mov    si,offset old_sep+1
  43.     mov    ah,47h
  44.     mov    dl,0
  45.     int    21h        ;get current path -> ds:si
  46. ;
  47. ; check if drive present
  48. ;
  49.     cmp    byte ptr es:[bx+1],':'
  50.     je    cp_drv_fnd        ;jmp if drive found
  51.     mov    si,bx
  52.         cmp     byte ptr es:[bx],'\'
  53.     je    cp_path_fnd        ;jmp if path without drive found
  54.     clc                ;do not return error, this is probably
  55.                     ; the debugger RUN.COM
  56.     jmp    change_path_exit    ;exit if drive not present
  57. ;
  58. ; switch to new drive at es:bx
  59. ;
  60. cp_drv_fnd:
  61.     mov    dl,es:[bx]    ;get drive letter
  62.     sub    dl,'A'
  63.     mov    ah,0eh
  64.     int    21h        ;switch to new drive
  65. ;
  66. ; switch to new path, but first extract info. from es:bx+1
  67. ;
  68.     mov    si,bx
  69.     add    si,2            ;skip past drive
  70. cp_path_fnd:
  71.     mov    di,offset new_path
  72.         cmp     byte ptr es:[si],'\'
  73.     je    mp_loop            ;jmp if directory present
  74.     mov    word ptr ds:[di],004ch
  75.     jmp    do_path_change
  76. mp_loop:
  77.     mov    al,byte ptr es:[si]
  78.     mov    byte ptr ds:[di],al
  79.     inc    si
  80.     inc    di
  81.     cmp    al,0
  82.     jne    mp_loop
  83. ;
  84. ; now scan back and remove executable file name
  85. ;
  86. mp_bak: dec    di
  87.         cmp     byte ptr [di],'\'
  88.     jne    mp_bak
  89.     mov    byte ptr [di],0
  90.  
  91. do_path_change:
  92.     mov    ah,3bh
  93.     mov    dx,offset new_path
  94.     int    21h
  95. change_path_exit:
  96.     pop    ds
  97.     retf    
  98. CHANGE_PATH    ENDP
  99. comment 
  100. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  DISK   )
  101. RESTORE_PATH - switch to directory saved by CHANGE_PATH
  102. ;
  103. ; inputs: none
  104. ; output: carry set if dos error
  105. ;* * * * * * * * * * * * * *
  106. 
  107.     public    restore_path
  108. RESTORE_PATH    PROC    FAR
  109.     mov    dl,cs:old_path
  110.     cmp    dl,0
  111.     je    rp_path_switch        ;jmp if drive not present
  112.     sub    dl,'A'
  113.     mov    ah,0eh
  114.     int    21h            ;switch drives
  115. ;
  116. ; switch paths
  117. ;
  118. rp_path_switch:
  119.     push    ds
  120.     mov    ax,cs
  121.     mov    ds,ax
  122.     cmp    old_sep,0
  123.     je    rp_exit            ;jmp if no path avail
  124.     mov    dx,offset old_sep
  125.     mov    ah,3bh
  126.     int    21h
  127.  
  128. rp_exit:
  129.     pop    ds
  130.     retf
  131. RESTORE_PATH     ENDP
  132.  
  133. LIBSEG    ENDS
  134.     end
  135.