It's simple enough, but overcomplicated

by (Login Mikrondel)

A processor has a bunch of address pins, a bunch of data pins, and a read/write pin.

If the read/write pin is set to read, this is understood as meaning "whoever is in charge of address [xyz] please tell send my data pins the appropriate data".

If the read/write pin is set to write, this is understood as meaning "whoever is in charge of address [xyz], I have placed some data on my data pins".

You may expect that if you write to some address and later read from the same address, you will get the same data that you previously wrote. THIS MAY NOT BE TRUE IF THE ADDRESS DOES NOT SIGNIFY A RAM CHIP.

For example, the BIOS is stored on ROM chips. You can write whatever the heck you want to address 0xFC000, but the writes will be ignored, and reads will always produce the same thing. The region 0xA0000 to 0xC0000 is mapped to the VGA card (which treats reads and writes differently in certain modes) and so on. Modern network cards, hard disk controllers, USB controllers, and such stuff all get memory regions assigned to them.

Note that only the OS can access these regions. When normal programs try to access "memory", they only ever get RAM.

Now, the overcomplicated part. Whether it was for making assembly programming easier or reducing chip costs or making it harder to blow up your system by mistake or other reasons, Intel decided to make TWO buses- the "memory bus" that was accessible with MOV instructions, and the "IO bus" that was accessible with INP/OUT instructions.

Nearly all I/O operations apart from text/graphics output on the PC were done with I/O ports. But these days they are rarely used except for legacy devices.

> I read that these two functions read and write directly to and from the given address, unlike PEEK and POKE

Under DOS, PEEK and POKE read and write directly to "memory space". INP and OUT read and write directly to "IO space". They're different hardware namespaces, if you like.

Under NTDVM and DOSBOX, PEEK and POKE access virtual memory, and INP and OUT are emulated or virtualised.

> what is the real difference?

The difference is some hardware operations are done with PEEK and POKE, and some hardware operations are done with INP and OUT. This is due to design choices made by IBM and other manufacturers. VGA for instance exposes its display memory in memory space but is configured (changing screen modes, etc.) in IO space. PEEK and POKE can also be used to access data in RAM and that sort of thing.

> How does QB64 deal with the fact that the ports are not the same as they were, and can't be accessed the same way either?

QB64 doesn't even use VGA itself, it uses the SDL library. So it would have to emulate VGA-related INP, OUT, PEEK and POKEs, and translate them to the SDL API where applicable.

> I don't understand how that prepares it to take input values. What hardware port is taking this color information?

IBM published a programming interface for VGA, and those port addresses and OUT procedures are described there. DOSBOX internally has a "virtual VGA card" that conforms to that interface. I believe (could be wrong) that when running fullscreen, NTVDM actually tries to get the graphics card into a compatible state and essentially lets the program talk to the graphics card almost directly. When running in pure DOS you actually DO have total access to the graphics card...

Posted on Jul 2, 2010, 8:28 PM

Respond to this message   

Return to Index

Response TitleAuthor and Date
*That was very informative, and will help a lot, thank you! on Jul 22

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement