A bit of confusion with splib + offsets

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

A bit of confusion with splib + offsets

Post by jordi »

It's strange but after creating two full games I am always having some trouble with sprite offsets.

From one side, I have these sprites:
https://github.com/jsmolina/speccy-misi ... prites.png

and their corresponding mask:
https://github.com/jsmolina/speccy-misi ... s_mask.png


All of them become .asm files on:
https://github.com/jsmolina/speccy-misi ... r.asm#L122

Sprite then is created by

Code: Select all

struct sp1_ss * sp;
   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);

  sp1_IterateSprChar(sp, initialiseColour);
  
And I move them just by setting offsets like:
#define RIGHTC1 16
#define RIGHTC2 80
#define LEFTC1 144
#define LEFTC2 208


So moving it becomes:

Code: Select all

sp1_MoveSprAbs(misifu.sp, &full_screen, (void*) misifu.offset, misifu.y, misifu.x, 0, 0); 

But for some weird reason, the cat is not FULLY displayed on all of its heigh (yellow is the visible part):
Image

I tried playing with '16' and so, but current value is the only one that seems to work.

You could find TAP file here: https://github.com/jsmolina/speccy-misi ... misifu.tap


My question is, am I missing something on regards of offset parameter? sp1_MoveSprAbs third param.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: A bit of confusion with splib + offsets

Post by Timmy »

Well, without something I can't compile and test with, this is going to be a guess. (and no, i'm not going to guess how you implement this.)

So all I can do for now is to check your assumptions.
jordi wrote: Sat Jan 02, 2021 10:57 pm And I move them just by setting offsets like:
#define RIGHTC1 16
#define RIGHTC2 80
#define LEFTC1 144
#define LEFTC2 208
So if these are offsets to your sprites data, then each sprite takes 64 bytes memory, correct? (80-16=64, 144-80=64)
But for some weird reason, the cat is not FULLY displayed on all of its heigh (yellow is the visible part):
Image
And these are the actual sprites right? Where each sprite has at least 3x3 tiles of 8x8 pixels, right? (at least, because we're not counting the extra buffers around them)

3x3 tiles of 8x8 pixels is like 3x3x8 = 72 bytes, correct?

So my first question is, how can your sprite offsets be 64, when you should have at least 72 bytes of sprite data? My guess is that you don't even have 72 bytes in you asm file for each sprite. And that you need to export your sprites again.

If this is not the answer then I really need something small to compile and check on.

EDIT: I was looking at the sprite data, and it seems you are drawing them in strips? Then it's even harder to guess what is going wrong if you don't show some code that only draw these sprites, because I'm not going to spend another hour to guess all your other assumptions for your sprites and data.
jordi
Member
Posts: 61
Joined: Sun Oct 28, 2018 3:35 pm

Re: A bit of confusion with splib + offsets

Post by jordi »

Hi Timmy, these sprites are supposed to be 24 pixels height.

Repo is here, feel free to do any modification. Compiling is as easy as typing 'make'.
https://github.com/jsmolina/speccy-misifu

I do use my own scripts to convert png to asm (png2sp1sprite is a python script in another repo if you are interested in rebuilding).
'protar.asm' is the cat.

Another question: newer versions changed from previous versions that used relative jumps on every frame (negative or positive), that's right? Churrera uses a very old version of splib, and they substract next frame, and current frame to get the offset.
jordi
Member
Posts: 61
Joined: Sun Oct 28, 2018 3:35 pm

Re: A bit of confusion with splib + offsets

Post by jordi »

I will create a simplier code example righ now:

https://github.com/jsmolina/simple_z88dk_sample

Maybe I did wrong what you did of the order of columns and frames?

build_asm.sh creates from png to asm
compile.sh creates tap
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: A bit of confusion with splib + offsets

Post by Timmy »

I've spent some hours to play with your code, and I think this code works:

Very little code has been changed, so I have no idea why this works and why your original code doesn't...

The "*9" is the number of sprites you have in your assembly file. Normally the parts of my sprites are stored next to each other and there's no need to do *9, but your sprite data are stored differently.

Code: Select all

#pragma output REGISTER_SP = 0xD000

#include <input.h>
#include <sound.h>
#include <arch/zx.h>
#include <arch/zx/sp1.h>
#include <intrinsic.h>
#include <z80.h>
#include <im2.h>
#include <string.h>

IM2_DEFINE_ISR(isr) {}
#define TABLE_HIGH_BYTE        ((unsigned int)0xD0)
#define JUMP_POINT_HIGH_BYTE   ((unsigned int)0xD1)

#define UI_256                 ((unsigned int)256)
#define TABLE_ADDR             ((void*)(TABLE_HIGH_BYTE*UI_256))
#define JUMP_POINT             ((unsigned char*)( (unsigned int)(JUMP_POINT_HIGH_BYTE*UI_256) + JUMP_POINT_HIGH_BYTE ))

extern uint8_t sprite_protar1[];
extern uint8_t sprite_protar2[];
extern uint8_t sprite_protar3[];

struct sp1_Rect full_screen = {0, 0, 32, 24};

int main()
{
  struct sp1_ss  *circle_sprite;
  unsigned char x;

  memset( TABLE_ADDR, JUMP_POINT_HIGH_BYTE, 257 );
  z80_bpoke( JUMP_POINT,   195 );
  z80_wpoke( JUMP_POINT+1, (unsigned int)isr );
  im2_init( TABLE_ADDR );
  intrinsic_ei();

  zx_border(INK_BLACK);

  sp1_Initialize( SP1_IFLAG_MAKE_ROTTBL | SP1_IFLAG_OVERWRITE_TILES | SP1_IFLAG_OVERWRITE_DFILE,
                  INK_BLACK | PAPER_WHITE,
                  'X' );
  sp1_Invalidate(&full_screen);

  circle_sprite = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 4, 0, 1);
  sp1_AddColSpr(circle_sprite, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, 64*9, 1);
  sp1_AddColSpr(circle_sprite, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, 128*9, 1);
  sp1_AddColSpr(circle_sprite, SP1_DRAW_MASK2RB,  SP1_TYPE_2BYTE, 0, 1);

  uint16_t  frame = 16;
  x=0;
  while(1) {
    x = 10;
    sp1_MoveSprAbs(circle_sprite, &full_screen,(int)sprite_protar1+frame - 16, 5, 5, 5, 5);
	sp1_UpdateNow();
    intrinsic_halt();
    intrinsic_halt();
	intrinsic_halt();

    if(in_key_pressed(IN_KEY_SCANCODE_0)) {
        frame = 16;
    } else if(in_key_pressed(IN_KEY_SCANCODE_1)) {
        frame += 64;
    } else if(in_key_pressed(IN_KEY_SCANCODE_2)) {
        frame -= 64;
    } else if(in_key_pressed(IN_KEY_SCANCODE_4)) {
        frame += 72;
    }
    //in_wait_nokey();
    // z80_delay_ms(100);
  }
}
jordi
Member
Posts: 61
Joined: Sun Oct 28, 2018 3:35 pm

Re: A bit of confusion with splib + offsets

Post by jordi »

Thanks for your great effort, Timmy. This way looks and feels perfectly.

Someone told me that padding between frames required same number of values as each column, but having just 8 seems to work ok, though.
Post Reply