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.
Simple tile drawing routines
Re: Simple tile drawing routines
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.)
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.)
Re: Simple tile drawing routines
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:
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:
In short, I'm looking for something that can do the same. Thanks again.
Code: Select all
._gameplayGraphics
defb @00011111
defb @00000111
defb @00000111
defb @00000001
defb @00000000
defb @00100000
defb @00000001
defb @00000001
.
.
Code: Select all
sp1_PrintAtInv(row, col, PAPER_BLACK|INK_CYAN, (uint16_t)&gameplayGraphics[tileNum * 8]);
Re: Simple tile drawing routines
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.
To avoid flicker you could add a sync checkpoint e.g. waiting for the timer being updated.
Re: Simple tile drawing routines
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.
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.
Re: Simple tile drawing routines
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.
Re: Simple tile drawing routines
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?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.
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)
Re: Simple tile drawing routines
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.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)
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.
Re: Simple tile drawing routines
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!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.
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.