How To

How does PEEK and POKE work?

1

S3B4 2019-01-08 11:54

I just don’t understand it, was8bit acts like it’s no big deal because he had it in his childhood but I don’t get how you can change the values and what values correspond to what. If you understand all that stuff can you give me a basic explanation. Please keep the answers simple.


Blockhead 2019-01-08 13:34

Peek is for view a saved variable and poke for save a variable but for now isn’t permanent


Timo 2019-01-08 13:58 (Edited)

It will be used for that too, but it’s more.
Peek reads a byte from the memory, poke writes one.
Actually “memory” is not only RAM, but also the (simulated) computer chips, like for graphics and sound.
In the manual these memory addresses are described in the chapter “Hardware Reference”.
In any case, almost everything you can do with normal BASIC commands, too. Peek and poke are more for hacking and some advanced stuff, but it’s usually not necessary.


was8bit 2019-01-09 04:47

Think if memory like mailboxes at a post office... mail gets sent to specific post office boxes by box #

In the same way, computer memory is referenced by "box#" or memory addresses... and each address (or box) holds one value ranging from 0 - 255

WHAT these addresses means depends on the person who has programmed the computer ... in this case, TIMO...

(By the way, it's a virtual computer)

The BASIC COMMANDS are made for easier use for us, but they actually read from or write to these addresses for us..

So, you can type BG 0 CELL 0,0,1 which puts character 1 in background 0 cell coordinate 0,0.... but behind the scenes what it does is out the value if 1 into memory address $9000 (this isn't precisely true as it also stores the value of the palette color number as well)

The memory list at the bottom of the HELP section lists the memory map, or memory addresses, and what they are used for by NX..

The BASIC commands we use actually peek and poke values into those memory spaces for us... we don't actually need to use PEEK and POKE, we can just use the BASIC commands for most all normal things...

However, if you want to write a TOOL like TIMO's CHAR DESIGNER or BG DESIGNER or such, PEEK and POKE are usefull...

Also, there are a few tricks you can use to create special effects.. I'll post example for you to check out :)


was8bit 2019-01-09 05:21

Check this out....

https://lowresnx.inutilis.com/topic.php?id=245


was8bit 2019-01-09 06:04

Also, this one...

https://lowresnx.inutilis.com/topic.php?id=246


S3B4 2019-01-09 11:14

Ok, thanks.


was8bit 2019-01-09 11:34 (Edited)

I loved the Apple2e computer

As an example, in APPLE2e all you have is a raw set of memory addresses... some RAM and some ROM... RAM = Read And write memory, ROM = Read Only memory.... ROM for example would hold the text character set, and other things...

then motherboard used some specific address for specific things, like for data to plot pixels on the screen...

The computer language (assembly language) was in hex code like $F1 or $A3 just raw numbers... a program in assembly language would just be a long list of such numbers stored in memory. So, as an example let's say $A3 was a command COPY A TO B so you would type in the numbers A335B2, A3 was the COPY command,,35 was the FROM memory address, and B2 was the TO address... a typo typically caused a program to crash....

But, most people used the BASIC programming which used LINE numbers in front of every text of code... rather than using GOTO REDRAW with REDRAW: label, you would use GOTO 2140 and on line #2140 you would have another basic command.... line numbers, then, where references to specific memory address in the computer memory which stored the basic commands.... made converting BASIC commands into ASSEMBLY commands straightforward..

And in BASIC commands you had PEEK and POKE which allowed you to look and place data into any memory location you wanted to... if you were not careful, you could POKE data into a place where your actual program was stored, which usually crashed your program...

However, if you wanted to crack a program by getting a look at its passwords in a program written in assembly language, and knew one of the passwords (for levels or such) and they didn't encrypt their passwords, you could use PEEK to scan thru their program until you found one password, and could eventually find all of their passwords.. by scanning thru every bit of their code ;)


was8bit 2019-01-09 11:41 (Edited)

TIMO made a virtual computer, to represent something like a GAMEBOY computer...

the text we type represents the GAME CARTRIDGE that would be stuck into the GAMEBOY and have not only the actual game code (which we write) but also all of the graphic data, music data, etc.. (which is the #2 CHARACTERS and such the TOOL EDITORS write)

So, then, when we play a game, it's like we are holding the GAMEBOY in our hands and playing the game we stuck into the player... hence the animation of a cartridge being put into the player :)

So, when you program in NX, TIMO created an experience as if you were programming a game for a GAMEBOY cartdrige, to be played on a GAMEBOY player :) (but not GAMEBOY, LOWRES NX player)


Log in to reply.