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
POKEP{Shift+O}971.0 to 2.x, 4.xCommand and Statement
POKE PO{Shift+K} 97 3.5, 7.0 Command and Statement 

 
Syntax 
POKE address value
 
ParametersTypeLegal Value(s)Default ValueNote(s)
addressUnsigned integer
0 to 65535
 
Pokes to ROM may "bleed" into underlying RAM.
valueUnsigned byte
0 to 255
 
 
 
Purpose 
Write contents of "memory".
 
 
Remarks 
This statement sets a value in "memory" which is typically RAM and can later be recalled with PEEK, or it may be (depending on the machine and the address) an I/O register instead.  In the later case, the value may not be retrievable, depending on the characteristics of the particular I/O register.  On machines with more than 64K of system RAM, the BANK statement should be used prior to POKE, so BASIC will access the correct "memory".
 
POKE is typically used to set (or alter) some feature of the computer that is not directly available from BASIC.  For example, on the C64, a POKE to address 53281 will change the background screen color (the color depends on the value).  In this case, the address corresponds to a VIC-II I/O register (not RAM).  The C64 has BASIC 2.1, but some later versions provide a BASIC command (COLOR) to set the screen color.  Another example is to POKE an address (or two) in RAM that will disable the STOP key so the user can't "break" a BASIC program.  This is an example of modifying the system behavior.
 
Another use, more common on versions without BLOAD, is to POKE a machine-language program into RAM.  Because a program is usually many many bytes, individual POKEs are not done, but a loop (with FOR/NEXT or DO/LOOP) is used in conjunction with DATA and READ statements.  The same method may rarely be used to store other non-program data into RAM, such as a custom font.  A combination of this method (POKE DATA that is READ in a LOOP) with the previous (writing to I/O registers) may sometimes be used to play music.
 
If the address or value is a string, a TYPE MISMATCH ERROR occurs.  Otherwise if either is not legal (see table above) then ILLEGAL QUANTITY ERROR is generated.
 
You can think of POKE as a machine-language equivalant of BASIC's LET.  Either way you can (generally) save a value; the main difference is that LET sets a BASIC variables while POKE sets a machine "variable" (using a loose definition).  To read a value from "memory", see PEEK.
 
The safe / useful set of address and value are very machine-specific; this statement is very 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.
POKE 254,-7

?ILLEGAL QUANTITY ERROR
READY.


 
Compare With 
 
Contrast With 
FN, PEEK, USR
 
 
See Also 

© H2Obsession, 2014