        page    ,132
        title   V86CODE\macro2.asm

.xlist
include v86seg.inc
.xcref
include mvdmexp.inc
include demsvc.inc
include struc30.inc
.cref
.list

V86SDA  SEGMENT
        EXTRN   CURDRV:BYTE
V86SDA  ENDS

V86CODE SEGMENT
        ASSUME  CS:V86GROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING
        EXTRN   Sys_Return:NEAR

subttl  $NameTrans - partially process a name
page

;
;INT 21h (AH=60h) $NameTrans         v86code\demfile.asm           #1/3
;INT 21h (AH=60h) [SVC]demNameTrans  mvdm\demfile2.asm             #2/3
;INT 21h (AH=60h) w_NameTrans        filesys\macro.asm             #3/3
;
;   $NameTrans - allow users to see what names get mapped to.  This call
;   performs only string substitution and canonicalization, not splicing.  Due
;   to Transpath playing games with devices, we need to insure that the output
;   has drive letter and :  in it.
;
;   Inputs:     DS:SI - source string for translation
;               ES:DI - pointer to buffer
;   Outputs:
;       Carry Clear
;               Buffer at ES:DI is filled in with data
;               ES:DI point byte after nul byte at end of dest string in buffer
;       Carry Set
;               AX = error_path_not_found
;   Registers modified: all
;
        ASSUME  DS:NOTHING,ES:NOTHING

public  $NameTrans
$NameTrans proc near

        SVC     SVC_DEMNAMETRANS

; If the CF is set, then just return it.
; We are looking for "\DEV\" on the front end of the returned string.
; This is the indicator for a device.  DOS 3.30, 4.0 and 5.0 all do
; not return the "\DEV\" front end.  So we must make it look like DOS.
        .if     nc
          .if     <<word ptr es:[di]> eq 'D\'> and
          .if     <<word ptr es:[di]+2> eq 'VE'> and
          .if     <<byte ptr es:[di]+4> eq '\'>

            mov     ax,[si]               ;\
            .if     <AH ne ':'>           ; \  If the user gave us a
              mov     al,[CURDRV]         ;  > drive, use it.  Else
              add     al,'A'              ; /  use the default drive.
            .endif                        ;/

            and     al,0DFh               ;convert AL to uppercase

            push    di                    ;preserve the DI register
            mov     es:[di],al
            inc     di                    ;new front end = "x:\"
            mov     ax,'/:'
            mov     es:[di],ax
            push    ax

            .repeat
              inc   di                    ;shift from "\DEV\....",0
              inc   di                    ;        to "x:\....",0
              mov   ax,es:[di]+2
              mov   es:[di],ax
            .until  <ZERO al> or
            .until  <ZERO ah>

            ; At this point we are DOS 3.30 compatible.
            ; For DOS 4.0 and 5.0 we need to add this:
            ;   if (byte es:[di] is not valid)
            ;   then begin
            ;        if (dos 4.0) then mov es:[di],'['
            ;        if (dos 5.0) then mov es:[di],'P'
            ;        end

            pop     ax                    ;AX='\:' is only being done
                                          ;to remain compatible.  There
                                          ;is no good reason for this.

            pop     di                    ;ES:DI is preserved.

          .endif
          clc
        .endif

        jmp     Sys_Return
$NameTrans endp

V86CODE ENDS

        END
