To compile to a .COM file all you need is:
.model tiny
ORG 100h
The DOS.SearchFirst function needs the CX
parameter. In order to search for any normal files specify CX=0
:
mov ah, 4Eh
xor cx, cx
mov dx, offset COM_FILE
int 21h
jc Done
Use this ASCIIZ filespec with wildcard:
COM_FILE db 'C:\EMU8086\MyBuild\*.com', 0
Since the default DTA (Disk Transfer Area) is at 80h, you're right to say: FNAME equ 9EH
.
If DOS found any matching file, its ASCIIZ filename will be at address 9Eh.
If however the DTA address was changed (normally that's something you would have done yourself via function 1Ah) you need to use the other address. You can always retrieve the current DTA address via function 2Fh. Result will be in ES:BX
.
I have installed emu8086 on C:\emu8086 and all the COM files I want to open is on C:\emu8086\MyBuild. Assembly files is in C:\emu8086\MySource. Now which one is the correct path?
If you still can't open the file it's probably because on the one hand you searched for it in a s p e c i f i c directory (C:\emu8086\MyBuild
) but on the other hand you try to open it in the c u r r e n t directory (???
).
The solution is to append the filename that DOS gave you to the same path that was used to ask for the file:
mov si, FNAME
mov di, FileName
More:
lodsb
stosb
cmp al, 0 ;Copy includes the terminating zero
jnz More
mov dx, Path
mov ax, 3D01h ;Access write-only
int 21h
jc OpenFileError
mov bx, ax ;Handle
With these data definitions:
COM_FILE db 'C:\EMU8086\MyBuild\*.com', 0
Path db 'C:\EMU8086\MyBuild\'
FileName db '.............'
MOV AX,3D01H;
MOV DX,FNAME;
INT 21H;
If a file can't be opened, DOS returns the CF set. Do check this!
MOV AH,40H;
MOV CL,42H;
MOV DX,100H;
INT 21H;
.Writing can fail. Check the CF!
.The size parameter is CX
not just CL
.
DONE:
RET
Although this works here (.COM program with an intact stack) you should make it a habbit to use the correct program termination code:
mov ax, 4C00h
int 21h