Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

My example does the following:

1. I have a painted sprite the size of 4x3 cells, it is drawn in BG.

I put it on the screen at position 0,0. The rest of the space BG and FG is empty.

2. Now I read 2-bit pixel values from the screen, combine two values into one 4-bit value and save it in a table

3. I write down all the values from the received table into memory. For clarity, I wrote them down in the FG area, but this area can be any.

4. Now I show how you can display a 2-bit image.

Also, for clarity, I used the palette of the 2-bit CGA palette

Here you can see the animation

-- title: 2-bit sprite
-- author: Al Rado
-- desc: shows how convert native TIC-80 4-bit sprite to 2-bit
-- script: lua
-- input: gamepad
-- pal: 00000000ffffff00ffffffff000000000000000000000000000000000000000000000000000000000000000000000000

SPRITE_ADDR=0x4000*2
NIBBLES_IN_SPR=64
SPR_IX=256
ADDR=SPRITE_ADDR+NIBBLES_IN_SPR*SPR_IX

SPR_W=4*8
SPR_H=3*8

-- convert native sprite to 2-bit sprite and save to memory
cls()
spr(0,0,0,-1,1,0,0,4,3)

local nibbles={}
for i=0,SPR_W*SPR_H-1 do
 nibbles[#nibbles+1]=pix(i%SPR_W,i/SPR_W) 
end

for i=1,#nibbles,2 do
 local first=nibbles[i] << 2
 local second=nibbles[i+1]
 poke4(ADDR+i//2, first+second) 
end

-- draw 2-bit screen from memory
local posX=50
local posY=50
for i=1,SPR_W*SPR_H,2 do
 local val=peek4(ADDR+i//2)
 local first=val >> 2
 local second=val - (first << 2)
 pix(posX+(i-1)%SPR_W,posY+(i-1)/SPR_W,first)
 pix(posX+(i)%SPR_W,posY+(i)/SPR_W,second)
end

function TIC()
 -- not implemented
end