-
-
Notifications
You must be signed in to change notification settings - Fork 505
poke4
poke4 addr4 val
- addr4 : the nibble (4-bit) address of RAM you desire to write (0 to 0x30000)
- val : the 4-bit integer value to write to RAM (0-15)
This function allows you to write directly to RAM. The address is often specified in hexadecimal format.
For both peek4
and poke4
RAM is addressed in 4 bit segments (nibbles). Therefore, to access the the RAM at byte address 0x4000 you would need to access both the 0x8000 and 0x8001 nibble addresses.
Note: Memory is sequenced with least significant nibbles first, which may be the opposite of what you expecting if you are reading the hexadecimal byte by byte. A small example:
-- set byte address 0x4000 to the value 0xF1 (241)
poke(0x4000, 0xF1)
-- the low nibble (least significant bits)
peek4(0x8000) -- => 1 (0x01)
-- the high nibble (most significant bits)
peek4(0x8001) -- => 15 (0x0F)
-- 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:
-- byte address | nibble address
-- 0x04000 | 0x08000 (low nibble)
-- | 0x08001 (high nibble)
-- 0x04001 | 0x08002 (low nibble)
-- | 0x08003 (high nibble)
-- 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
TIC-80 tiny computer https://tic80.com | Twitter | Telegram | Terms
Built-in Editors
Console
Platform
RAM & VRAM | Display | Palette | Bits per Pixel (BPP) |
.tic
Format | Supported Languages
Other
Tutorials | Code Snippets | Libraries | External Tools | FFT
API
- BDR (0.90)
- BOOT (1.0)
- MENU
- OVR (deprecated)
- SCN (deprecated)
- TIC
- btn & btnp
- circ & circb
- clip
- cls
- elli & ellib (0.90)
- exit
- fget & fset (0.80)
- font
- key & keyp
- line
- map
- memcpy & memset
- mget & mset
- mouse
- music
- peek, peek4
- peek1, peek2 (1.0)
- pix
- pmem
- poke, poke4
- poke1, poke2 (1.0)
- rect & rectb
- reset
- sfx
- spr
- sync
- ttri (1.0)
- time
- trace
- tri & trib (0.90)
- tstamp (0.80)
- vbank (1.0)