Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wondering what uses poke/peek could have(just started qbasic)

Status
Not open for further replies.

qbiscool

Programmer
Feb 18, 2004
33
CA
i am a newbie to qbasic, i have been writing it for maybie 2 months and i just learned how to use the poke/peek function and i was wondering what use there could be for it

so far i all i have been useing it for is to change variables.

any halp would be appreceiated

thanks
 
PEEK and POKE are used to work with the inner working of the computer, mainly the RAM. It allows you to directly access it rather than letting qbasic do it for you (which takes more time.) PEEK allows you to read information and POKE allows you to store information.

As I said it is mainly used for RAM access, but it can also be used to access your printer, monitor, ports, mouse, keyboard, etc.

You should also take a look at the OUT and INP functions, they also work with the inner parts of your computer.

If you have a question about how and where to reach certain parts of your computer please follow up and we will be glad to help.
 
I'm using PEEK and POKE, along with IN and OUT, to do all the graphics for my RPG-in-progrsss, Quest for a King ( Once you know where certain things are held in memory, you can use peek and poke to find out stuff about the current configuration, or change stuff, like the aforementioned graphics stuff.

If you're new to QB though, I'd recommend you learn stuff a bit less advanced for now. Though it's incredibly useful, it's of no use to you if you don't have the knowlege base to do something with it. Might I recommend string manipulation, file handling, the various things you can do with arrays, how to implement various simple algorithms in QB without resorting to pointers and such? :)
 
Yes, until you learn a bit more,I would stick to the more basic stuff. PEEK and POKE can reach many parts of the computer, and if you POKE the wrong information to the wrong place it can really mess your computer up.
 
thanks for the help. i was just wondering if poke/peek could help me whith a contest im entering on the contest is to create a screensaver in nine lines.
i no i have no hope of winning but i thought it would be fun to try becouse when it is over they show all the screen savers.

thanks for the help.
 
is poke/peek the kind of thing that you would use to open the cd drive or turn the moniter on or off. i think that would be interesting to know
 
Yes, those are the kinds of things PEEK and POKE could theoretically be used for. I'd have to look up if you can open your cd drvier, but the address for the monitor is 966. POKE 966, 0 to turn it off: 966, 255 to turn it on.
 
my mistake, those should be OUT 966, 0 and OUT 966, 255. Sorry about that.
 
k thanks for the information. i was wondering about the cd drive becouse every time i log on to the internet here my cd drive opens and i was wondering if there was something i could do to stop it. it says its spyware
 
if i had a program that had to be able to tell if it is the first time running on a computer or not could i use poke. so that if it is the first time running i could show the password and then i would poke a variable. maybe like:


if firsttime > 1 then exit sub
else if firsttime = 0 then print "password is ????"

i have tryed bsave/bload and i cant figure it out.
 
PEEK/POKE are mostly used in graphic oriented programming, because of the above mentioned reason (speed). INP and OUT, althought they have a lot to do with graphics, ten to be used more for sound and other internal procedures. Check out INTTERUPT and ABSOLUTE as well as the X version of each command. As a newbie, I would suggest steering clear of this stuff until you are a little more fluent in qbasic, or you might get bogged down, or screw up your computer. But, you will get the hang of it quickly.
 
i got the peek/poke and out/inp figured out and i started writing plasma and pallette manipulation with them so thanks for the info
 
To truly understand peek and poke and what they do you would have to learn ASM although I don't reccomend u do that yet.

Well, peek reads memory and poke writes to it. Don't worry if you accedentally do something wrong and put in wrong values. You can't mess up the ROM and when you accidentally mess up the RAM (when working under windows) windows will most likely have some kind of error box pop up and close qb. The DEF SEG is important as to where you write and read. You see the whole memory in DOS is all segmented. It has a segment and then an offset (although the do overlap). Like this: 116C:0100 is 1 byte (8 bits, 0 - 255)in memory where poke can write to or peek can read from. The segment in that is 116C (a Hex #) and the offset is 0100 (also hex). There are special places in memory where certain data is stored. For example: As you probably already know that in the qb world right now poke is mainly used for graphics in SCREEN 13. The segment of the beginning of that is A000 (Hex) thus u need to tell qbasic that since qbasic's POKE just tells the offset and you have to set the segment using DEF SEG.

To draw graphics you woould then:

SCREEN 13

DEF SEG = &HA000 ; tell the segment

POKE 0, 1 ; the mem address A000:0000 is cordinate (0,0)
; and is set to 0, but by poking 1 into it you
; change that mem addresses value into 1 thus
;making a blue pixel at coordinate (0,0)

There are many other special memory adresses used for many different things so you should try to go to different qb websites and finding them out if you want
 
here is some sample code I made to get the status of a joystick(it uses poke/peek)

CLS
SCREEN 12
10 'Begining
A% = INP(&H201)
LOCATE 1, 1: PRINT "Current:"
LOCATE 1, 9: PRINT A%
'OUT &H201, B%
LOCATE 2, 1: PRINT "Base:"
LOCATE 2, 6: PRINT PEEK(0)
X = PEEK(1)
IF PEEK(1) = 1 THEN F = PEEK(0) - A%
LOCATE 3, 1: PRINT "Final:"
LOCATE 3, 7: PRINT F
IF F = 16 THEN LOCATE 4, 1: PRINT "Button#1"
IF F = 32 THEN LOCATE 4, 1: PRINT "Button#2"
IF F = 64 THEN LOCATE 4, 1: PRINT "Button#3"
IF F = 48 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2"
IF F = 80 THEN LOCATE 4, 1: PRINT "Button#1 & Button#3"
IF F = 96 THEN LOCATE 4, 1: PRINT "Button#2 & Button#3"
IF F = 112 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2 & Button#3"
IF F = 128 THEN LOCATE 4, 1: PRINT "Button#4"
IF F = 144 THEN LOCATE 4, 1: PRINT "Button#1 & Button#4"
IF F = 160 THEN LOCATE 4, 1: PRINT "Button#2 & Button#4"
IF F = 176 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2 & Button#4"
IF F = 192 THEN LOCATE 4, 1: PRINT "Button#3 & Button#4"
IF F = 208 THEN LOCATE 4, 1: PRINT "Button#1 & Button#3 & Button#4"
IF F = 224 THEN LOCATE 4, 1: PRINT "Button#2 & Button#3 & Button#4"
IF F = 240 THEN LOCATE 4, 1: PRINT "Button#1 & Button#2 & Button#3 &Button#4"
PRINT " "; SPACE$(40)
IF X = 0 THEN GOTO 20
IF X = 1 THEN GOTO 10
20 'Store A% Value
POKE 0, A%
POKE 1, 1
GOTO 10
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top