Peek And Poke Article Index for
Peek
Shopping
PEEK
 

Information About

Peek And Poke




In Computing , PEEK is a BASIC Programming Language function used for reading the contents of a memory cell at a specified Address . The corresponding command to set the contents of a memory cell is '''POKE'''.


STATEMENT SYNTAX


The PEEK function and POKE command are usually invoked as follows, either in direct mode (entered and executed at the BASIC Prompt ) or in indirect mode (as part of a Program ):

''integer_variable'' = PEEK(''address'')

POKE ''address'', ''value''

  • , as long as the evaluation of those expressions end up as valid memory addresses or values, respectively. A valid ''address'' in this context is an address within the computer's total Address Space or the CPU s addressing range, whichever is the smallest, while a valid ''value'' is (typically) an unsigned value between zero and the maximum unsigned number that the minimum addressable unit (memory cell) may hold.†


Example: A typical early 1980s Home Computer could have 32 KB Main Memory and an 8-bit microprocessor CPU with a 16-bit address range, leading to the following restrictions on PEEK and POKE parameter values:

0 <= ''address'' <= 32767 ; comment: 32767 = 32 K -1 = 2 ^ 15-1, i.e. smaller than the CPU's 16-bit address range
; from 0 to 65535 = 64K-1 = 2^16-1

0 <= ''value'' <= 255 ; comment: 255 = 2^8-1, i.e. the maximum value of an 8-bit Byte

  • A slightly complex-looking POKE-statement might look like this: POKERARRAY(42),PEEK(B1ADDR+(ASC(T9TXTS$))-VARRAY(42)) (where combinations of various BASIC functions and variables are used to build the parameters, and the Interpreter allows Space characters to be left out.) )


(† Plain, straightforward limits on PEEK/POKE parameters—i.e., values restricted by address range/memory and word width—may for various reasons be amended by the BASIC interpreter/compiler designers, e.g. such as to allow for signed input values and/or outside address range/memory space address values; reasons for this could be e.g. to simplify certain operations by hiding unnecessary complexity from the BASIC programmer. In such a scheme, the PEEK and POKE machine code sequences within the interpreter/compiler must compute valid memory access parameters, of course.)


MEMORY CELLS AND HARDWARE REGISTERS


The address locations POKEd to or PEEKed from may refer either to ordinary memory cells or to 's built-in VIC-II graphics chip, will make the screen border turn black:

POKE 53280, 0

Different pre/non- PC computers usually differ as to the memory address areas designated for user programs, user data, operating system code and data, and memory-mapped hardware units. Because of all this, PEEK fuctions and POKE commands are inherently Non-portable , meaning that a given sequence of those statements will almost never work on any other system than the one the program was written for.


POKES AS CHEATS


In the context of games for many 8-bit computers, it was a usual practice to load games into memory and, before lauching them, modify specific memory addresses in order to cheat, getting an unlimited number of lives, immunity, invisibility, etc. Such modifications were performed through POKE sentences. Commodore 64 also allowed, with proper cartridges, to freeze the running program, enter POKEs, and resume.

For instance, with

POKE 47196, 201

in Knight Lore for ZX Spectrum , immunity is achieved. Magazines like Microhobby used to publish lists of such POKEs for games. Of course, in order to find them someone had to read the machine code and locate the critical point where the number of lives is decreased, impacts detected, etc. Sometimes the term '''POKE''' was used with this specific meaning.


GENERIC USAGE OF "POKE"


"POKE" is sometimes used as a generic term to refer to any direct manipulation of the contents of memory, rather than just via BASIC, particularly among people who learned computing on the 8-bit Microcomputer s of the late 70s and early 80s. BASIC was often the only language available on those machines (on Home Computers , usually present in ROM ), and therefore the obvious, and simplest, way to program in Machine Language was to use BASIC to POKE the Opcode values into memory. Doing much low-level coding like this usually came from lack of access to an Assembler .



SEE ALSO