how to create masked foregrounds with sp1

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
fraespre
Member
Posts: 56
Joined: Mon Aug 19, 2019 8:08 pm

how to create masked foregrounds with sp1

Post by fraespre »

Hi, I would like to create a masked foreground with sp1.
Of course I could use the usual sprites, but I suppose that will be a waste of memory because in the foregrounds case is not necessary the rotations.

I've noticed there are some functions in the sp1 api for this. But I haven't found any tutorial neither example.

Code: Select all

// some functions for displaying independent struct_sp1_cs not connected with any sprites; useful as foreground elements
// if not using a no-rotate (NR) type sprite draw function, must manually init the sp1_cs.ldef member after calling sp1_InitCharStruct()
extern void sp1_InitCharStruct(struct sp1_cs *cs,void *drawf,uint16_t type,void *graphic,uint16_t plane);
extern void sp1_InsertCharStruct(struct sp1_update *u,struct sp1_cs *cs);
extern void sp1_RemoveCharStruct(struct sp1_cs *cs);
Could you help me to prepare an example.

foreground.c

Code: Select all

#pragma output REGISTER_SP = 0xD000

#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 unsigned char circle_masked[];
extern unsigned char foregr_masked[];

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

int main() {
  struct sp1_ss  *circle_sprite;
  struct sp1_cs  *p_instance_cs;
  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();

  sp1_Initialize( SP1_IFLAG_MAKE_ROTTBL | SP1_IFLAG_OVERWRITE_TILES | SP1_IFLAG_OVERWRITE_DFILE, INK_BLACK | PAPER_WHITE, 'X' );
  sp1_Invalidate(&full_screen);
 
  // sp1_ss *sp1_CreateSpr(void *drawf,uint16_t type,uint16_t height,int graphic,uint16_t plane);
  circle_sprite = sp1_CreateSpr(SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, 2, (int)circle_masked, 5);
  sp1_AddColSpr(circle_sprite, SP1_DRAW_MASK2RB, SP1_TYPE_2BYTE, 0, 0);

  struct sp1_cs instance_cs= { 
                   0,                                                                //struct sp1_cs     *next_in_spr; 
                   0,                                                                 //struct sp1_update *update;    
                   0,                                                                //uint8_t              plane;   
                   circle_sprite->first->type,                //uint8_t              type;        
                   circle_sprite->first->attr_mask,//uint8_t              attr_mask;    
                   circle_sprite->first->attr,                //uint8_t              attr; 
                   0,                                                                //void                *ss_draw;
                   circle_sprite->first->res0,                //uint8_t              res0; 
                   0,                                                                //uint8_t             *def; 
                   circle_sprite->first->res1,                //uint8_t              res1; 
                   circle_sprite->first->res2,                //uint8_t              res2; 
                   0,                                                                //uint8_t             *l_def;
                   circle_sprite->first->res3,                //uint8_t              res3;  
                   circle_sprite->first->draw,                //void                *draw; 
                   0,                                                                //struct sp1_cs       *next_in_upd; 
                   0                                                                //struct sp1_cs       *prev_in_upd;
        };
  p_instance_cs= &instance_cs;

  // sp1_InitCharStruct(struct sp1_cs *cs, void *drawf, uint16_t type, void *graphic, uint16_t plane);
  sp1_InitCharStruct(p_instance_cs, SP1_DRAW_MASK2LB, SP1_TYPE_2BYTE, (int)foregr_masked, 0);

  x=0;
  while(1) {
    sp1_MoveSprPix(circle_sprite, &full_screen, 0, x++, 4);
    intrinsic_halt();
    intrinsic_halt();
    sp1_UpdateNow();
  }
}
foreground.asm

Code: Select all

SECTION rodata_user

PUBLIC _circle_masked

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

._circle_masked
        defb @11000011, @00111100
        defb @10000001, @01000010
        defb @00000000, @10000001
        defb @00000000, @10000001
        defb @00000000, @10000001
        defb @00000000, @10000001
        defb @10000001, @01000010
        defb @11000011, @00111100

PUBLIC _foregr_masked

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

._foregr_masked

        defb @11111111, @00000000
        defb @11111111, @00000000
        defb @11111111, @00000000
        defb @11111111, @00000000
        defb @00000000, @11111111
        defb @00000000, @11111111
        defb @00000000, @11111111
        defb @00000000, @11111111
In this example, I would like include a new component (foregr_masked).

But I have 2 general doubts:

- How Should I initialize sp1_cs struct ? (I have put a lot of ceros and I've copied some values of the other sprite because I don't know what value to set)

- After to invoke the "sp1_InitCharStruc", how Should I to print it in the screen ?


Thanks in advanced,
Post Reply