Splib + fonts (FZX?)

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

Splib + fonts (FZX?)

Post by jordi »

Hi,

I might be confused, but I was checking how to use fonts in my new game, but I didn't found the way to go.
I'm theorically using my own font, but now I don't know how to print it on the screen.


https://github.com/jsmolina/z88dk-tutor ... l/45/files

In theory I'm replacing _ff_ao_Prefect.asm as I read in another thread here, but I don't know how it connects to the API.

I'm usually painting with
sp1_PrintAt(0, 2, INK_WHITE | PAPER_BLACK, '1');
sp1_PrintAt(0, 3, INK_WHITE | PAPER_BLACK, 'U');
sp1_PrintAt(0, 4, INK_WHITE | PAPER_BLACK, 'P');
sp1_PrintAt(0, 5, INK_WHITE | PAPER_BLACK, '-');

Of course I could replace 1, U, P with the UDGs and it will work, but it will be so memory uneficient.
But I guess that's not the way to go, so I got lost on printing texts and showing with proper font instead of default ones.


Lot of thanks, again
Timmy
Member
Posts: 135
Joined: Sat Mar 10, 2012 4:18 pm

Post by Timmy »

Ok, a couple of things...

1) fzx is pretty much incompatible with splib... one of them uses a buffer while the other prints directly on screen. There are probably ways to go around them but i never really bother.

2) Here's a sample from my game on how i do fonts (I probably borrowed it from somewhere else, too):

// Setting up some letters, but not all...
sp1_TileEntry(33, font1);
for (i=1; i<46; i++)
{
sp1_TileEntry(45+i, font1+i*8);
}

where font is an array with udgs, and

void printatstr(uchar y, uchar x, uchar attr, uchar *s)
{
uchar xx, i;
xx = x; i=0;
while (s)
{ sp1_PrintAt( y, xx++, attr, s[i++]); }
}

then I can do things like:

printatstr(0, 2, INK_WHITE | PAPER_BLACK, "1UP-");

2a) This is not much memory inefficient because splib already has a list of locations of every letter already. sp1_PrintAt is however very slow.

3) In some other games, where I have a background buffer myself, I'd change the buffer instead and then blit the whole buffer on screen instead... This isn't faster but it changes whole screen with one command. See also my sp1 demo program for this. (I don't have a link right now.)
derekfountain
Member
Posts: 34
Joined: Mon Mar 26, 2018 1:49 pm

Post by derekfountain »

jordi wrote:I'm theorically using my own font, but now I don't know how to print it on the screen.
Yes, I got my font into SP1 the same way as Timmy. Then sp1_PrintString will work as you'd hope.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

Hi, lot of thanks to both of you!!!!

Just a bit of self-marketing, but I did this two scripts in python:
https://github.com/jsmolina/png2sp1spri ... 2sp1sprite

png2udg converts a 8x8 (or 8*N x 8) udg to an asm file, suitable to be easily compiled. So you can edit your PNG in Photoshop and just leave your Makefile compiling the modified file, forgetting about external programs.
png2sp1sprite does the same, but for sprintes. Supports animated sprites and (theoretically) masks.
jordi
Member
Posts: 51
Joined: Sun Oct 28, 2018 3:35 pm

Post by jordi »

Sorry but posts can't be edited. The cat looks like:

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;
}

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, 1);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar2, 1);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar3, 1);
  sp1_AddColSpr(sp, SP1_DRAW_MASK2,    SP1_TYPE_2BYTE, (int)sprite_protar4, 1);

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

  sp1_IterateSprChar(sp, initialiseColour);

  return sp;
}
Here it says (sorry, in spanish) that first goes sprite info, then mask info:
https://wiki.speccy.org/cursos/z88dk/sprites3

but example is outdated from current api, and that's what confuses me a lot.
Post Reply