×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

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.

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

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 (http://powerusr.rpg-dev.net). 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? :)

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

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.

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

(OP)
thanks for the help. i was just wondering if poke/peek could help me whith a contest im entering on www.qbnz.com.
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.

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

(OP)
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

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

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.

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

my mistake, those should be OUT 966, 0 and OUT 966, 255.  Sorry about that.

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

(OP)
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

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

(OP)
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.

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

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.

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

How do you PEEK and POKE in SCREEN 9?

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

(OP)
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

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

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

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close