Efficient expansion of monochrome (1bpp) bitmap in screen 7?

By DamnedAngel

Expert (70)

DamnedAngel's picture

13-08-2018, 14:57

Hi all,

Given a monochrome (1bpp) bitmap in an inactive VRAM page and a color, is it possible anyhow to copy it colorized to an active VRAM page (screen mode 7), or I will have to copy the bitmap to RAM and iterate every pixel to generate the expanded 4bpp bitmap (although with only 1 color) and then copy it back to VRAM?

thanks in advance!

Login or register to post comments

By Grauw

Enlighted (7356)

Grauw's picture

13-08-2018, 22:12

Yep, there’s no trick to make the VDP do that for you. I would use VRAM access to read the data and then copy it back over simultaneously with HMMC, or just keep the bitmap in RAM.

(I think the V9990 can do it though, with CMMM.)

By DamnedAngel

Expert (70)

DamnedAngel's picture

15-08-2018, 02:02

Hi Grauw,

Thanks for the reply. That is what I though, but...

What did you mean by "simultaneously"?

TIA,

By PingPong

Prophet (3123)

PingPong's picture

15-08-2018, 03:22

DamnedAngel wrote:

Hi all,

Given a monochrome (1bpp) bitmap in an inactive VRAM page and a color, is it possible anyhow to copy it colorized to an active VRAM page (screen mode 7), or I will have to copy the bitmap to RAM and iterate every pixel to generate the expanded 4bpp bitmap (although with only 1 color) and then copy it back to VRAM?

thanks in advance!

assuming each byte represent 8 consecutive pixels on axis, you can fill a 1K bytes area with precalculated 4 bpp values.
each byte value point to a 8 pixels 4bpp colors encoded values that is 4 bytes.
During expansion read a byte value (1bpp) do some math and index the four bytes to poke into vram. then outi the four bytes.

for example the binary 00100001 means two background pixels followed by 1 foreground pixel then four background pixels then 1 foreground pixel. Assuming you use color 0 for background and color 15 for foreground you need to poke 4 bytes:
0000 0000 b-> 0 (decimal)
1111 0000 b-> 240 decimal
0000 0000 b-> 0 (decimal)
0000 1111 b-> 15 (decimal)

so if you have a precalculated table like this you can do something like this:

ld a,(bc) -> point to 1bpp image, get the byte
ld h, 0
ld l,a
add hl,hl  -> multiply by four
add hl,hl 
ld de, base_precalculated_table_address
add hl,de
outi
outi
outi
outi
My MSX profile