Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

PEEK

Keyword Abbreviation Token (hex) Version(s) Classification
PEEK P{Shift+E} C2 1.0 to 4.7 Function
PEEK  PE{Shift+E}  C2  7.0  Function 

  Syntax  
PEEK ( address )
 
Parameters Type Legal Value(s) Default Value Note(s)
address Unsigned integer
0 to 65535
 
In v1.0, PEEK of ROM would return 0.
 
Returns Type Value(s) Note(s)
value Integer
0 to 255
 
  Purpose  
Read contents of "memory".
 
 
Remarks  
This statement gets a single byte, value, from "memory" which may be RAM, ROM, or (not really memory) an I/O register.  In the later case, the simple act of "reading" may cause the I/O chip to update the value (it might change automically too, depending on the type of chip).  On machines with more than 64K of system RAM, the BANK statement should be used prior to PEEK, so BASIC will access the correct "memory".  It is also possible there is nothing connected to the specified address, however BASIC will not generate an error in such a case; you simply get "garbage."
 
PEEK is typically used to retrieve a piece of information about the hardware or some secret BASIC setting (such as the current DATA pointer) that is not directly available from BASIC.  For example, on the C64, a PEEK of address 53281 will give the value that the VIC-II is using for the background screen color.  In this case, the C64 has BASIC 2.1, but some later versions provide a BASIC command (RCLR) to get the current screen color.
 
If the address is a string, a TYPE MISMATCH ERROR occurs.  If address is a floating-point value it will converted to an integer (see INT).  If the (resulting) integer is not legal (see table above) then ILLEGAL QUANTITY ERROR is generated.
 
This function is the complement of POKE which lets you write "memory."  The useful set of addresses is very machine-specific; this function is non-portable.  As such, there are no examples... okay one stupid example that should be safe on any CBM machine.
 
Example:
POKE 254,7

READY.
PRINT PEEK(254)
 7

READY.
PRINT PEEK(-254)

?ILLEGAL QUANTITY ERROR
READY.
  
 
Compare With  
 
Contrast With  
 
See Also  

© H2Obsession, 2014
Comments