Simple tile drawing routines

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
clebin
Member
Posts: 15
Joined: Wed Mar 23, 2022 6:28 pm

Simple tile drawing routines

Post by clebin »

Hello all. I recently started on my second z88dk game. I'm currently using SP1 as before but it's massive overkill for what I need and I need to free up RAM. I'm looking for some simple code block or library I can drop in to save precious RAM. Maybe what I need is built into z88dk already?

These are the functions I need:

* Print 8x8 tiles at a specific coordinates like sp1_PrintAtInv() etc
* Stamp a masked image on top of a 8x8 tile (this is for a cursor that's overlaid over a tile but only moves a block at a time - no need for pixel movements)

It's a strategy game rather than an arcade one, so my requirements are fairly easy but I do want to avoid flicker.

I realise this is trivial stuff but I don't write assembly myself (for now). Thanks in advance.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Simple tile drawing routines

Post by Timmy »

We've had the exact question earlier this year at viewtopic.php?p=20350

In short, there's somehow no simple routine to put a simple tile onto the screen in z88dk just for the Spectrum.

In that thread I've linked my own solution of a simple routine to print a character on screen.

I have nothing for putting a masked character yet. If you need something really specific then you can let me know.

(Of course in my own games (which includes strategy games) I have a library to just draw simple tiles, but it might not be what you want.)
clebin
Member
Posts: 15
Joined: Wed Mar 23, 2022 6:28 pm

Re: Simple tile drawing routines

Post by clebin »

Thanks very much Timmy. I missed that thread I think because I'm looking at graphics rather than characters, but I'll give your WOS thread & code a good look tonight. Maybe it'll help if I share a bit of code. I have some graphics defined like this with 8-bytes for each tile:

Code: Select all

._gameplayGraphics

defb @00011111
defb @00000111
defb @00000111
defb @00000001
defb @00000000
defb @00100000
defb @00000001
defb @00000001
.
.

I then use SP1 to plot it to the screen. The SP1 can either take a character or a 16-bit memory location, which is how I'm using it:

Code: Select all

sp1_PrintAtInv(row, col, PAPER_BLACK|INK_CYAN, (uint16_t)&gameplayGraphics[tileNum * 8]);
In short, I'm looking for something that can do the same. Thanks again.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Simple tile drawing routines

Post by stefano »

Not the best choice ever, but putsprite does it.
To avoid flicker you could add a sync checkpoint e.g. waiting for the timer being updated.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Simple tile drawing routines

Post by jorgegv »

Also to avoid filckering you can do what SP1 does: temporarily read the previous screen data into an 8-byte buffer, do your operations with the buffer (masking, ORing, XORing, whatever with your new tile...) and transfer the modified buffer back into the original place on the screen.

This way you don't need to sync with the display, since you will be always writing new data to the screen whith contains the "old" data.

Not the fastest way, though.
clebin
Member
Posts: 15
Joined: Wed Mar 23, 2022 6:28 pm

Re: Simple tile drawing routines

Post by clebin »

stefano wrote: Mon Nov 14, 2022 5:13 pm Not the best choice ever, but putsprite does it.
To avoid flicker you could add a sync checkpoint e.g. waiting for the timer being updated.
Thanks for the tips! putsprite looks like a good solution for the cursor. It needs extra bytes for dimensions and padding so I won't use it for the tiles/blocks.
clebin
Member
Posts: 15
Joined: Wed Mar 23, 2022 6:28 pm

Re: Simple tile drawing routines

Post by clebin »

jorgegv wrote: Tue Nov 15, 2022 8:06 am Also to avoid filckering you can do what SP1 does: temporarily read the previous screen data into an 8-byte buffer, do your operations with the buffer (masking, ORing, XORing, whatever with your new tile...) and transfer the modified buffer back into the original place on the screen.

This way you don't need to sync with the display, since you will be always writing new data to the screen whith contains the "old" data.

Not the fastest way, though.
That's interesting, ta! With that in mind, could I use one of the UDGs as a buffer and use a standard routine to print it to the screen? Modifying the UDG wouldn't change what's already been printed screen I take it? How fast would it be to do it that way?

I'd be happy to keep sp1 if I could use it with bank-switching, but I have my data at 0x6000-0x7FFF, my code at 0x8000-0xBFFF and then sp1 at 0xD000 on. I'd like to switch banks to display a cut-scene, but that would rely on sp1 still being there. (and I can't get it to function in newlib at all)
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Simple tile drawing routines

Post by jorgegv »

clebin wrote: Tue Nov 15, 2022 9:22 am I'd be happy to keep sp1 if I could use it with bank-switching, but I have my data at 0x6000-0x7FFF, my code at 0x8000-0xBFFF and then sp1 at 0xD000 on. I'd like to switch banks to display a cut-scene, but that would rely on sp1 still being there. (and I can't get it to function in newlib at all)
In my RAGE1 engine, I'm doing bank switching and I have moved lots of engine functions to banks without issues, BUT: SP1 is the single thing that I haven't been able to move. It has huge memory requirements (12K just for the screen tile buffer itself!), so it needs a bank almost entirely for itself.

I'm doing what you want to do, though (have cut-scenes in banks) and I have done it... without using SP1. I'm using SP1 for the game, but for the cut-scenes I have a dedicated print routine which also lives in the cut-scenes bank, and I use that instead of SP1 for the display. Since the routine is simple, it does not matter much to have duplicated code for blitting.
clebin
Member
Posts: 15
Joined: Wed Mar 23, 2022 6:28 pm

Re: Simple tile drawing routines

Post by clebin »

jorgegv wrote: Tue Nov 15, 2022 9:32 am I'm doing what you want to do, though (have cut-scenes in banks) and I have done it... without using SP1. I'm using SP1 for the game, but for the cut-scenes I have a dedicated print routine which also lives in the cut-scenes bank, and I use that instead of SP1 for the display. Since the routine is simple, it does not matter much to have duplicated code for blitting.
This inspired me to move loads more of my code into banks and separate it from anything that uses sp1. I also finally figured out why the bank-switching was working so inconsistently. It was a combination of things, but the final piece was that the stack was still registered at 0xD000 - stupid!

I think I can get away with keeping sp1 and shovelling graphics out of higher banks as needed. So, it's game on! Thanks again.
Post Reply