poke4 - winnichenko/BLOB-87 GitHub Wiki
poke4
poke4 addr4 val
Parameters
- addr4 : the nibble (4 bits) address in RAM to which to write,
- val : the 4-bit value (0-15) to write to the specified address
Description
This function allows you to write to the virtual RAM of TIC. It differs from poke in that it divides memory in groups of 4 bits. Therefore, to address the high nibble of position 0x4000 you should pass 0x8000 as addr4, and to access the low nibble (rightmost 4 bits) you would pass 0x8001. The address should be specified in hexadecimal format, and values should be given in decimal.
Example
-- title: poke4/peek4 example
-- author: PaulR
-- script: Lua
-- This example reads and writes into
-- sprite memory so we can see the
-- effect directly
-- Sprites are stored from address
-- 0x04000 onwards. Memory can be
-- addressed in 8 or 4 bit form so
-- we can access sprite memory as follows:
-- 8 bit address | 4 bit address
-- 0x04000 | 0x08000 (high nibble)
-- | 0x08001 (low nibble)
-- 0x04001 | 0x08002 (high...)
-- | 0x08003 (low...)
-- write color 5 to first pixel of sprite 0
poke4(0x08000,5)
-- write color 10 to next pixel of sprite 0
poke4(0x08001,10)
function TIC()
cls(0)
-- display sprite 0
spr(0,0,0)
-- the two pixels set by our poke4
-- commands are visible
-- display the 8 bit value stored at 0x04000
print(peek(0x04000),30,30,4)
-- prints '165'
-- ie value of 10 shifted left by 4
-- into the high nibble (10<<4=160)
-- plus 5 in the low nibble
-- show our color values using
-- 4 bit addressing
print(peek4(0x08000),30,40,4)
print(peek4(0x08001),30,50,4)
end
See also: Spritesheet editing example in the examples page