PICO-8 Wiki
Advertisement
peek2( addr, [n] )
Reads one or more 16-bit values from contiguous groups of two consecutive memory locations.
addr
The address of the first memory location.

n
The number of values to return. (1 by default, 8192 max.)

The peek2() function reads and returns 16-bit values from groups of two consecutive bytes in the addressable memory region (0x0000-0x7fff). The value is interpreted in the Little Endian representation, which stores the lowest 8 bits in the first byte.

See Memory for information about the memory layout.

% operator[]

The unary-% operator added in 0.2.0 performs the same function as peek2(address) and is now the recommended way to read one 16-bit word of memory at a time, as it uses fewer tokens, costs fewer cycles at runtime, and runs on the real host CPU much more efficiently. Simply replace peek2(address) with %address.

Examples[]

poke(0x4300, 0xff, 0x0c)

b = peek2(0x4300)  -- 0x0cff, or 3327 in decimal

b = %0x4300        -- preferred method

See also[]

Advertisement