But there is a much more important reason not to try accessing the hardware directly
(unless, of course, you are writing a device driver), even on the UNIX like systems that let you do it:
UNIX is an
There is a major difference in the philosophy of design between MS-DOS and UNIX. MS-DOS was designed as a single-user system. It is run
on a computer with a keyboard and a video screen attached directly to that computer. User
input is almost guaranteed to come from that keyboard. Your program's output virtually
always ends up on that screen.
This is NEVER guaranteed under UNIX. It is quite common
for a UNIX user to pipe and redirect program input and
% program1 | program2 | program3 > file1
If you have written program2, your input does not come from
the keyboard but from the output of program1. Similarly, your
output does not go to the screen but becomes the input for program3 whose output, in turn, goes to file1.
But there is more! Even if you made sure that your input comes from, and your output
goes to, the terminal, there is no guarantee the terminal is a PC: It may not have its
video memory where you expect it, nor may its keyboard be producing PC-style scan codes. It may be a Macintosh®, or any other computer.
Now you may be shaking your head: My software is in PC assembly language, how can it run on a Macintosh? But I did not say your software would be running on a
Macintosh, only that its terminal may be a Macintosh.
Under UNIX, the terminal does not have to be directly
attached to the computer that runs your software, it can even be on another continent,
or, for that matter, on another planet. It is perfectly possible that a Macintosh user in Australia connects to a UNIX system in North America (or anywhere else) via telnet. The software then runs on one computer, while the
terminal is on a different computer: If you try to read the scan codes, you will get the
Same holds true about any other hardware: A file you are reading may be on a disk you
have no direct access to. A camera you are reading images from may be on a space shuttle,
connected to you via satellites.
That is why under UNIX you must never make any
assumptions about where your data is coming from and going to. Always let the system
handle the physical access to the hardware.
Note: These are caveats, not absolute rules. Exceptions are possible. For
example, if a text editor has determined it is running on a local machine, it may want to
read the scan codes directly for improved control. I am not mentioning these caveats to
tell you what to do or what not to do, just to make you aware of certain pitfalls that
await you if you have just arrived to UNIX form MS-DOS. Of course, creative
people often break rules, and it is OK as long as they know they are breaking them and