diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-05-05 21:39:32 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-05-05 21:40:34 +0100 |
commit | ca551c1700cf982fe96388491a096b515365894f (patch) | |
tree | e40b9a95cb1f0169c553c19da4ff52c16e73035a | |
parent | f10e1ea20cbadd151b20175f48ac902eac4ee0d7 (diff) | |
download | tr8vm-ca551c1700cf982fe96388491a096b515365894f.tar.gz tr8vm-ca551c1700cf982fe96388491a096b515365894f.zip |
Use the MSB of the index to mark a transparent color
Because we use 1 byte to store 4bpp, we don't need a mask and we can
encode a "transparent" color in the bits we don't use.
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | assets/icon.png | bin | 641 -> 5802 bytes | |||
-rw-r--r-- | example.asm | 9 | ||||
-rw-r--r-- | tr8as.c | 7 |
4 files changed, 16 insertions, 6 deletions
@@ -236,8 +236,10 @@ Read the file and add the content to the output at current position. .incpng "filename" Read the PNG image and add the content to the output at current position. The -image colours will be matched with the TR8 palette and any non-matchin color -will be condiered transparent and the image will be included with a mask. +image colours will be matched with the TR8 palette and any non-matching color +will be condiered transparent and the index `128` will be used. + +The blitter won't draw any pixel with index larger than 15. #### Load and Store diff --git a/assets/icon.png b/assets/icon.png Binary files differindex 0890b92..e216044 100644 --- a/assets/icon.png +++ b/assets/icon.png diff --git a/example.asm b/example.asm index 73aa9a5..2ab0ee7 100644 --- a/example.asm +++ b/example.asm @@ -75,7 +75,16 @@ draw_sprite: line: push x ld x, [a : x] + + ; any color with index > 15 + ; is transparent + cmp x, 16 + bnc + jmp transparent + ld [b : y], x + +transparent: pop x inc x @@ -495,12 +495,11 @@ static uint8_t parse_incpng(As *as, char **c) goto exit_parseinc; } - /* TODO: mask */ - uint16_t addr = as->addr; uint8_t index; - /* map RGB values to the palette indexes */ + /* map RGB values to the palette indexes; + * any index over 15 is "transparent" with index 128 */ for (int i = 0; i < x * y * 3; i += 3) { for (index = 0; index < 16; index++) @@ -512,7 +511,7 @@ static uint8_t parse_incpng(As *as, char **c) break; } if (index == 16) - as->out[addr++] = 0; + as->out[addr++] = 128; } as->addr = addr; |