Poke and Peek
Poke and Peek are slightly more advanced versions of QB's PSET and POINT commands respectively. They are used because they are a good bit faster than the BASIC commands. This is because they directly access the video buffer, and write directly to the screen memory. They only work in screen 13(and maybe 7? Never tried) because they're the only resolutions with 320x200, which, if you multiply it out, comes out to 64000. This is important, because QB can't deal with numbers larger than this(at least not in integers). Also, the other screen modes(such as 12) are divided into 4 different areas of 320x200 each, and each has a different memory address. This can get very complicated, so I won't go into it.
First I will discuss POKE, because that's probably what most people use most.
Poke is basically a faster pset, with slightly different code. Here's what I mean:
screen 13
def seg = &HA000
poke(y * 320& + x), col
def seg
Make sure you don't forget the second def seg, or you will have major memory problems on your system. It resets the default segment to normal. Now I'll go over it line by line. Hopefully you know what screen 13 is. DEF SEG = &HA000 sets the default segment to the screens memory location(&HA000). poke(y * 320& + x), col actually plots the point in the screen memory. It is supposed to be y*320&, or you get overflow errors. It looks at the screen as if it were paper to be written on, and writes from right to left and top to bottom like normal. What y*320& does is move the point to be plotted over 320 pixels the number of times y is equal to. +x then moves it over the number of pixels needed for x and there you have it.
That may have been just a little confusing, but you have the code from above to poke pixels, so if you don't entirely understand it, that's pretty much okay(I'm sure someone's going to yell at me for saying that.)
Now, peek is similar to poke, but it returns a value rather than writing one. Here's a quick example and then I'll go over it line by line again.
screen 13
def seg = &HA000
variable=peek(some memory address)
def seg
Once again, screen 13 to start. Def seg sets it to the screen buffer, and in this case, variable=peek(some memory address), the some memory address would be y*320&+x again, but that changes with what you're using it for. Then we have another def seg.
Using the screen buffer as the segment means that we're going to return the color of a pixel this time. Use the same coordinate system as it was for poke. This time variable will hold the color number of that particular pixel. This is often used for collision detection in games, but use it however is handy.
I think that covers pretty much everything about poke and peek, but if it doesn't, give me a buzz at the address at the bottom of the page.
Back to the Tutorials...
E-Mail: cybertron@flashmail.com