first of all, are you familiar with hexadecimal numbers? If not, it would be a good idea to become familiar with them, as memory addresses are almost always in hexadecimal numbers. In QBASIC, hexadecimal numbers are preceded by &H, whereas in almost everything else, they are preceded by 0x. In short, it is a base 16 number system, using numerals "0" to "f".
QBASIC 1.1 was designed to run in x86 "real mode".
This means that memory addresses will have a 16 bit segment and a 16 bit offset. These are usually separated by a colon. So, for example, the CGA color text mode buffer starts at memory address:
&hb800 : &h0
Where &hb800 is the segment, and &h0 is the offset.
In "real mode", the linear memory address is determined by multiplying the segment by 16 (hex: &h10), and adding it to the offset. So the linear address would be &hb80000. You could, for example, get the same linear address with a segment/offset of &hb7ff:&h10, but there's usually no reason to mess around like that.
Let's say that you want to write directly to the CGA color text buffer. It starts at &hb800:0000, and it is an array of byte pairs. One byte for the character value, the next byte for the color attribute.
In QBASIC, you set the segment with DEF SEG, like this:
DEF SEG = &HB800
Then you can PEEK and POKE while specifying the offsets.
DEF SEG = &HB800 ' CGA color text buffer
POKE 0, 1 ' smiley face chr$(1)
POKE 1, &H1F ' blue, bright white
POKE 2, 4 ' diamond chr$(4)
POKE 3, &HCE ' blinking, red, bright yellow
Have a look at the program in this post:
It should be said that the x86 "real mode" is quite obsolete. QB64 gives you 32 bit (or 64 bit) offsets.
|Response Title||Author and Date|
|thanks||nick on Jul 18|
|a little more...||on Jul 18|