Mail Archives: djgpp/2000/02/27/04:48:27
On Sun, 27 Feb 2000, Lin wrote:
> I can excute both code image on WIN95's DOS box without any problem.
> it create a new file name RESLT.DAT ok.
> but at plain DOS (both 7.0 and 6.22) both code will just show messup
> code on screen.
This is expected: your code calls Int 21h from protected mode:
> mov edx,file_name
> mov ah,3ch ; create the a file and get handle
> mov cx,0
> int 21h
This will *never* work in plain DOS, because you need to issue Int 21h
in REAL MODE. The reason for this is that DOS is a real-mode
operating system, so its code cannot run when the CPU is in protected
mode.
The reason it works on Windows is that Windows includes a built-in DOS
extender, which catches Int 21h calls made from protected mode and
does the necessary magic (described below) behind the scenes. But on
DOS you need to do this yourself.
There's a special function of Int 31h, the DPMI API interrupt, which
was designed for this: it switches the CPU into real mode, reissues
Int 21h, then switches the CPU back to protected mode. Note that you
need to copy the file name and the data you want to write to the
transfer buffer, because DOS cannot access memory above 1MB mark,
where your protected-mode program runs.
This is all explained in sections 18.1, 18.2 and 18.4 of the DJGPP FAQ
list. I suggest to read it.
Alternatively, you could call library functions _creat, _write, and
_close, they do all this for you.
- Raw text -