creating masks for splib sprites

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

creating masks for splib sprites

Post by jordi »

How masks should be stored?

I do have animated sprite as:
Image

and masks as
Image

so... how mask is represented in the sprite?
Something like this? defb @MASK_8_bits, @SPRITE_8_bits

Code: Select all

._sprite_protar1_f1

 defb @11111111, @11111001
 defb @11111101, @11111010
I've been trying without luck.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

just an appointment: eyes should be white, but it's corrected that on my version.

Lot of thanks for the help.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

derekfountain
Member
Posts: 34
Joined: Mon Mar 26, 2018 1:49 pm

Post by derekfountain »

Masked sprites are discussed in the second SP1 getting started article, here.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

derekfountain wrote:Masked sprites are discussed in the second SP1 getting started article, here.
Thankyou, but if I follow tutorial something weird happens:


1) I have drawn the tutorial 'circle' and compiled using my own code, and the result is here:
https://github.com/jsmolina/png2sp1spri ... masked.asm
(as you see it is 1:1 tutorial binary data)

2) but used, in the good old misifu, it causes weird painting:
Image



sprites are:
https://github.com/jsmolina/speccy-misi ... prites.png

while mask:
https://github.com/jsmolina/speccy-misi ... s_mask.png
derekfountain
Member
Posts: 34
Joined: Mon Mar 26, 2018 1:49 pm

Post by derekfountain »

I don't know what you mean by "in the good old misifu".

I picked up your 'circle' code from your Github page and it works correctly. The sprite_sample.png and sprite_sample_mask.png are correctly converted by my local copy of the png2sp1sprite utility and the example works as expected.

Does your example work for you?
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

derekfountain wrote:I don't know what you mean by "in the good old misifu".

I picked up your 'circle' code from your Github page and it works correctly. The sprite_sample.png and sprite_sample_mask.png are correctly converted by my local copy of the png2sp1sprite utility and the example works as expected.

Does your example work for you?
yep, the example worked perfectly.

Sorry, Misifu is a game that I did for ZXDev, that I'm improving graphics with a guy.

What I mean is that on
https://github.com/jsmolina/speccy-misifu/
repository I am trying to do the same as the example of the circle, so cats mask is:

https://github.com/jsmolina/speccy-misi ... s_mask.png

And cat sprites is:
https://github.com/jsmolina/speccy-misi ... prites.png

But I got the weird result you saw before.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

maybe the difference is how I create the sprite?

Code: Select all

struct sp1_ss * add_sprite_protar1() {
  struct sp1_ss * sp;
   sp = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 3, (int)sprite_protar1, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar2, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar3, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar4, 0);

  sp1_AddColSpr(sp, SP1_DRAW_MASK2RB,  SP1_TYPE_2BYTE, 0, 0);

  sp1_IterateSprChar(sp, initialiseColour);

  return sp;
}

Code: Select all

static void initialiseColour(unsigned int count, struct sp1_cs *c)
{
  (void)count;    /* Suppress compiler warning about unused parameter */

  c->attr_mask = SP1_AMASK_INK;
  c->attr      = INK_BLACK;
}
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

might be related as the sprite is animated?? it's the only diffence with the circle
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

SOLVED!!!
It was related to frame param, I was sending wrong values.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

Lot of thanks!
derekfountain
Member
Posts: 34
Joined: Mon Mar 26, 2018 1:49 pm

Post by derekfountain »

Heh, good timing, I was just about to start trying to work it out myself. Glad you solved it. :)
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

derekfountain wrote:Heh, good timing, I was just about to start trying to work it out myself. Glad you solved it. :)
I lied finally, it is driving me crazy the param named 'void *frame' in 'sp1_MoveSprAbs'.

Specially, when sprite has MASK and ANIMATION at the same time.

Let's say I have my cat in this asm file:
https://github.com/jsmolina/speccy-misi ... protar.asm

Original file is 216x24. So each frame has 24 pixels with both mask and pixel data, having some padding bytes before.

Which is the right value for each frame then? I am usually calculating, but then getting weird results.

Sprite is created this way

Code: Select all

   sp = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 4, (int)sprite_protar1, 1);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar2, 0);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar3, 0);

  sp1_AddColSpr(sp, SP1_DRAW_MASK2RB,  SP1_TYPE_2BYTE, 0, 0);
So third param is 4, that means 3 tiles + 1. I saw I always have to sum +1 on the heigh parameter of create.

Then drawing the cat with sp1_MoveSprAbs shoudl be frame == 0, then what is next? how I sum up?


Thanks, and sorry for disturbing.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

And this is another example, that seems to work right for a 16x16 px sprite with mask and frames.

I use these frame values. I don't like because I usually do it "try and error". That means that probably I am doing it wrong.

Code: Select all

#define AUX_PHONE 4
#define AUX_ZAP 52  // + 16x2 + 8x2
#define AUX_ARROWRIGHT 100
#define AUX_ARROWLEFT  148
#define AUX_BROOM 196
#define AUX_BROOM2 244
asm code will look like

Code: Select all

SECTION rodata_user

; Original: 96, 16 (=12 x 2 chars)
; Blocks: 2
; mask, sprite
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

PUBLIC _auxiliar1
._auxiliar1

._auxiliar1_f1
 defb @11111111, @00000000
 defb @11110000, @00000000
 defb @11000000, @00001111
 defb @10000000, @00111011
 defb @00000000, @01110100
 defb @00000000, @01110110
 defb @00000000, @00000111
 defb @11100000, @00001111
 defb @11100000, @00001100
 defb @11000000, @00011001
 defb @11000000, @00011010
 defb @11000000, @00011001
 defb @11000000, @00011100
 defb @11000000, @00011111
 defb @11100000, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f2
 defb @11111111, @00000000
 defb @11111110, @00000000
 defb @11111100, @00000001
 defb @11101000, @00000011
 defb @11000000, @00010010
 defb @10000000, @00110100
 defb @00000000, @01110111
 defb @00000000, @11010100
 defb @00000000, @10010000
 defb @00000001, @00100100
 defb @10000001, @00101100
 defb @10000011, @00111000
 defb @10000111, @00110000
 defb @10001111, @00100000
 defb @10011111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f3
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11110111, @00000000
 defb @11100011, @00001000
 defb @11110001, @00000100
 defb @11111000, @00000010
 defb @11111100, @00000001
 defb @11111110, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f4
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111110, @00000000
 defb @11100100, @00000001
 defb @11100000, @00001010
 defb @11100001, @00001100
 defb @11100000, @00001110
 defb @11100000, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f5
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111000, @00000001
 defb @11110000, @00000111
 defb @11100000, @00001111
 defb @11100000, @00001111
 defb @11000000, @00011111
 defb @11000000, @00000110

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar1_f6
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111110, @00000000
 defb @11111100, @00000001
 defb @11111100, @00000001
 defb @11111000, @00000011
 defb @11111000, @00000011
 defb @11111000, @00000011
 defb @11111000, @00000010

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

PUBLIC _auxiliar2
._auxiliar2

._auxiliar2_f1
 defb @11111111, @00000000
 defb @00001111, @00000000
 defb @00000011, @11110000
 defb @00000001, @11011100
 defb @00000000, @00101110
 defb @00000000, @01101110
 defb @00000000, @11100000
 defb @00000111, @11110000
 defb @00000111, @00110000
 defb @00000011, @01011000
 defb @00000011, @10011000
 defb @00000011, @01011000
 defb @00000011, @00111000
 defb @00000011, @11111000
 defb @00000111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f2
 defb @11111111, @00000000
 defb @01111111, @00000000
 defb @00100111, @10000000
 defb @00000011, @10011000
 defb @00000001, @11011100
 defb @00000000, @11010110
 defb @00000000, @11010010
 defb @00000000, @11010110
 defb @00000000, @01011100
 defb @00000000, @01010001
 defb @00000000, @00010011
 defb @11000000, @00000110
 defb @11100001, @00000000
 defb @11100011, @00001000
 defb @11100011, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f3
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @01111111, @00000000
 defb @00100111, @10000000
 defb @00000111, @01010000
 defb @10000111, @00110000
 defb @00000111, @01110000
 defb @00000111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f4
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11101111, @00000000
 defb @11000111, @00010000
 defb @10001111, @00100000
 defb @00011111, @01000000
 defb @00111111, @10000000
 defb @01111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f5
 defb @11100111, @00000000
 defb @11100011, @00001000
 defb @11000011, @00011000
 defb @11000111, @00010000
 defb @10000111, @00110000
 defb @10001111, @00100000
 defb @00001111, @01100000
 defb @00011111, @01000000
 defb @00011111, @11000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @01111111, @00000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000

._auxiliar2_f6
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00111111, @10000000
 defb @00011111, @11000000
 defb @00001111, @11100000
 defb @00001111, @11100000
 defb @00000111, @11110000
 defb @00000111, @11000000

 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
 defb @11111111, @00000000
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

Is there anything I can do to make this easier in the future?

To be honest I thought my sp1 example explained a lot already.

But maybe I need to make a tutorial for sp1 then? (Can't promise that it will be good, just that I can make one.)
fraespre
Member
Posts: 21
Joined: Mon Aug 19, 2019 8:08 pm

Post by fraespre »

Timmy wrote:Is there anything I can do to make this easier in the future?
To be honest I thought my sp1 example explained a lot already.
But maybe I need to make a tutorial for sp1 then? (Can't promise that it will be good, just that I can make one.)
Personally I think sp1 has some functionalities little or no documented.

For example:
- sp1_IterateUpdateArr
- Functions for displaying independent struct_sp1_cs not connected with any sprites (foregrounds)
https://github.com/z88dk/z88dk/blob/mas ... h/zx/sp1.h

I would appreciate some simple example to demonstrate these features. And avoid guessing what the assembly code does :-D

Thanks in advanced
Post Reply