INT 21h AH=47h copies the current directory of a drive into the buffer at DS:SI. The buffer is in SI, not DX as in most services. What comes back is the path in capitals, ending with a 0 byte, with neither the drive nor the backslash after it:
| Current directory | The buffer |
|---|---|
| C:\ | 0 (an empty string) |
| C:\TOOLS | "TOOLS", 0 |
| C:\TOOLS\BIN | "TOOLS\BIN", 0 |
To show a full path, print the drive letter (from INT 21h AH=19h), ":\", then the buffer. 64 bytes are always enough: DOS does not let a path, drive included, grow beyond 64 characters. The drive is numbered from 1 = A, with 0 for the current drive; a drive that does not exist gives CF = 1 and AX = 15 (0Fh, invalid drive). On success MS-DOS happens to return AX = 0100h, and DOSBox-X does the same, but nothing promises it.
MOV AH, 47h ; DOS: the current directory of drive DLMOV DL, 0 ; 0 = the current drive, 1 = AMOV SI, OFFSET PATH1 ; DS:SI = 64 bytes for the pathINT 21hMOV AH, 19h ; 47h leaves out the drive: print it firstINT 21hADD AL, "A"MOV DL, ALMOV AH, 02hINT 21hMOV DL, ":"MOV AH, 02hINT 21hMOV DL, "\" ; and the backslash after itMOV AH, 02hINT 21hCLDMOV SI, OFFSET PATH1NEXT1:LODSB ; the path ends with a 0 byteOR AL, ALJZ DONE1MOV DL, ALMOV AH, 02hINT 21hJMP NEXT1DONE1:MOV DX, OFFSET CRLFMOV AH, 09hINT 21hMOV DX, OFFSET BADM1MOV AH, 09hINT 21hMOV AH, 47h ; a drive that cannot existMOV DL, 27MOV SI, OFFSET PATH1INT 21hCALL RESULT ; error 15: invalid drivePATH1 DB 64 DUP(0)BADM1 DB "drive 27: $"RESULT PROC NEAR ; print "ok", or "error" and AX when CF = 1PUSHF ; keeps AX and CF for the callerPUSH AXMOV DX, OFFSET OKMSGJNC RESULT1MOV DX, OFFSET ERRMSGMOV AH, 09hINT 21hPOP AXPUSH AXCALL PDEC ; the error codeMOV DX, OFFSET CRLFRESULT1:MOV AH, 09hINT 21hPOP AXPOPFRETRESULT ENDPOKMSG DB "ok", 13, 10, "$"ERRMSG DB "error $"PDEC PROC NEAR ; print AX in decimal (changes AX BX CX DX)MOV BX, 10XOR CX, CX ; digits on the stackPDEC1:XOR DX, DXDIV BX ; AX = AX / 10, DX = the last digitPUSH DXINC CXOR AX, AXJNZ PDEC1PDEC2:POP DX ; the digits come back first to lastADD DL, "0"MOV AH, 02hINT 21hLOOP PDEC2RETPDEC ENDPCRLF DB 13, 10, "$"
47h always returns 8.3 names. In DOSBox-X a host folder with a long name appears as its generated short name, such as PROGRA~1, the name DIR shows and CD accepts. With long file names enabled, function 7147h of INT 21h returns the long form.