-
-
Notifications
You must be signed in to change notification settings - Fork 505
poke4
Josh Goebel edited this page Mar 28, 2021
·
14 revisions
poke4 addr4 val
- 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
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.
-- 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
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)