Home
CBM
  ASCII-X
  BASIC
    Disk Commands
    Enter RUN mode
    Program Format
    Secret Variables
    Variable Format
    Expressions
    Keywords
      (divide)
      (equal)
      (less)
      (minus)
      (more)
      (multiply)
      (plus)
      (power)
      Abs
      And
      Append
      Asc
      Atn
      Auto
      Backup
      Bank
      Begin
      Bend
      Bload
      Boot
      Box
      Bsave
      Bump
      Catalog
      Char
      Chr
      Circle
      Close
      Clr
      Cmd
      Collect
      Collision
      Color
      Concat
      Cont
      Copy
      Cos
      Data
      Dclear
      Dclose
      Dec
      Def
      Delete
      Dim
      Directory
      Dispose
      Dload
      Do
      Dopen
      Draw
      Ds
      Ds string
      Dsave
      Dverify
      El
      Else
      End
      Envelope
      Er
      Err
      Exit
      Exp
      Fast
      Fetch
      Filter
      Fn
      For
      Fre
      Get
      Get num
      Getkey
      Go
      Gosub
      Goto
      Graphic
      Gshape
      Header
      Help
      Hex
      If
      Input
      Input num
      Instr
      Int
      Joy
      Key
      Left
      Len
      Let
      List
      Load
      Locate
      Log
      Loop
      Mid
      Monitor
      Movspr
      New
      Next
      Not
      Off
      On
      Open
      Or
      Paint
      Peek
      Pen
      Pi
      Play
      Pointer
      Poke
      Pos
      Pot
      Print
      Print num
      Pudef
      Quit
      Rclr
      Rdot
      Read
      Record
      Rem
      Rename
      Renumber
      Restore
      Resume
      Return
      Rgr
      Right
      Rlum
      Rnd
      Rreg
      Rspcolor
      Rsppos
      Rsprite
      Run
      Rwindow
      Save
      Scale
      Scnclr
      Scratch
      Sgn
      Sin
      Sleep
      Slow
      Sound
      Spc
      Sprcolor
      Sprdef
      Sprite
      Sprsav
      Sqr
      Sshape
      St
      Stash
      Step
      Stop
      Str
      Swap
      Sys
      Tab
      Tan
      Tempo
      Then
      Ti
      Ti string
      To
      Trap
      Troff
      Tron
      Until
      Using
      Usr
      Val
      Verify
      Vol
      Wait
      While
      Width
      Window
      Xor
    Syntax
    Tokens
  C128
  D64plus
  Disk
  Escape Codes
  Hardware
  PCxface
  PETSCII
  Pet2asc
Futurama
IBM PC-AT
Contact
Games
Glossary
Hall of fame
Hall of shame
Miscellaneous
Privacy policy
Programming
Twisty puzzles
KeywordAbbreviationToken (hex)Version(s)Classification
PEEKP{Shift+E}C21.0 to 4.7Function
PEEK PE{Shift+E} C2 7.0 Function 

 Syntax 
PEEK ( address )
 
ParametersTypeLegal Value(s)Default ValueNote(s)
addressUnsigned integer
0 to 65535
 
In v1.0, PEEK of ROM would return 0.
 
ReturnsTypeValue(s)Note(s)
valueInteger
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