PeekPoke

From s23
Jump to navigation Jump to search

PEEK TYPE: Integer Function FORMAT: PEEK(<numeric>)

Action: Returns an integer in the range of 0 to 255, which is read from a memory location. The <numeric> expression is a memory location which must be in the range of 0 to 65535. If it isn't then the BASIC error message ?ILLEGAL QUANTITY occurs. EXAMPLES of PEEK Function:

  10 PRINT PEEK(53280) AND 15   (Returns value of screen border color)
  5 A%=PEEK(45)+PEEK(46)*256    (Returns address of BASIC variable table)

POKE TYPE: Statement FORMAT: POKE <location>,<value>

Action: The POKE statement is used to write a one-byte (8-bits) binary value into a given memory location or input/output register. The <location> is an arithmetic expression which must equal a value in the range of 0 to 65535. The <value> is an expression which can be reduced to an integer value of 0 to 255. If either value is out of its respective range, the BASIC error message ?ILLEGAL QUANTITY occurs.

The POKE statement and PEEK statement (which is a built-in function that looks at a memory location) are useful for data storage, controlling graphics displays or sound generation, loading assembly language sub- routines, and passing arguments and results to and from assembly language subroutines. In addition, Operating System parameters can be examined using PEEK statements or changed and manipulated using POKE statements. A complete memory map of useful locations is given in Appendix G.

http://www.devili.iki.fi/Computers/Commodore/C64/Programmers_Reference/Chapter_2/page_069.html


Here is an example of a program using multi-color programmable characters:

10 REM * EXAMPLE 2 *
20 REM CREATING MULTI COLOR PROGRAMMABLE CHARACTERS
31 POKE 56334,PEEK(56334)AND254:POKE1,PEEK(1)AND251
35 FORI=0TO63:REM CHARACTER RANGE TO BE COPIED FROM ROM
36 FORJ=0TO7:REM COPY ALL 8 BYTES PER CHARACTER
37 POKE 12288+I*8+J,PEEK(53248+I*8+J):REM COPY A BYTE
38 NEXT J,I:REM GOTO NEXT BYTE OR CHARACTER
39 POKE 1,PEEK(1)OR4:POKE 56334,PEEK(56334)OR1:REM TURN ON I/O AND KB
40 POKE 53272,(PEEK(53272)AND240)+12:REM SET CHAR POINTER TO MEM. 12288
50 POKE 53270,PEEK(53270)OR16
51 POKE 53281,0:REM SET BACKGROUND COLOR #0 TO BLACK
52 POKE 53282,2:REM SET BACKGROUND COLOR #1 TO RED
53 POKE 53283,7:REM SET BACKGROUND COLOR #2 TO YELLOW
60 FOR CHAR=60TO63:REM PROGRAM CHARACTERS 60 THRU 63
80 FOR BYTE=0TO7:REM DO ALL 8 BYTES OF A CHARACTER
100 READ NUMBER:REM READ 1/8TH OF THE CHARACTER DATA
120 POKE 12288+(8*CHAR)+BYTE,NUMBER:REM STORE THE DATA IN MEMORY
140 NEXT BYTE,CHAR
150 PRINT"{CLEAR}"TAB(255)CHR$(60)CHR$(61)TAB(55)CHR$(62)CHR$(63)
160 REM LINE 150 PUTS THE NEWLY DEFINED CHARACTERS ON THE SCREEN
170 GET A$:REM WAIT FOR USER TO PRESS A KEY
180 IF A$=""THEN170:REM IF NO KEYS WERE PRESSED, TRY AGAIN
190 POKE53272,21:POKE53270,PEEK(53270)AND239:REM RETURN TO NORMAL CHARS
200 DATA129,37,21,29,93,85,85,85: REM DATA FOR CHARACTER 60
210 DATA66,72,84,116,117,85,85,85: REM DATA FOR CHARACTER 61
220 DATA87,87,85,21,8,8,40,0: REM DATA FOR CHARACTER 62
230 DATA213,213,85,84,32,32,40,0: REM DATA FOR CHARACTER 63
240 END