Wiping the Screen

7-21-2018
This is a pretty simple task, but I do want to do a quick write-up on it.

We do have occasions where we want to clear our screen, this task will come in handy for a few upcoming features that we will be using.

All we really need to do is create a loop where we can step through the screen block by block (16-pixel character blocks) and populate it with a blank tile. Next, we will need to step through all of the sprites and clear each one.

Here’s the code.

 void clearScreen()
{
screenScanX = 0;
screenScanY = 0;
//clear the screen
for (screenCounter = 0; screenCounter < 150; ++ screenCounter)
{
if (screenScanX == 15)
{
screenScanX = 0;
++ screenScanY;
}
if (screenScanY == 10)
{
screenScanY = 0;
screenScanX = 0;
}
tiles[screenScanY * scrw + screenScanX]= 0;
tilepaint(screenScanX, screenScanY, screenScanX, screenScanY);
FRAME;
++ screenScanX;//move over a column
}
//clear the sprites
for (screenCounter = 0; screenCounter < 5; ++ screenCounter )
{
sprites[screenCounter].n = 129;
FRAME;
}
screenScanX = 0;
screenScanY = 0;
}

We’ve used this type of loop before, so there is no reason to explain it, however, the lines

tiles[screenScanY * scrw + screenScanX]= 0;
tilepaint(screenScanX, screenScanY, screenScanX, screenScanY);
FRAME;

You may find interesting.

tiles[screenScanY * scrw + screenScanX]= 0;

Places in the tile array, that we want a tile 0, which is a blank tile. We populate that array with blank tiles. However, that does not immediately translate to a blank screen. The next line does.

tilepaint(screenScanX, screenScanY, screenScanX, screenScanY);

Tilepaint is a function in FASE that will paint the tile indicated with the start X position and Start Y position and finish with the end X position and end Y position.

tilepaint(Start X, Start Y, End X, End Y);

Is the format of the function.

The next line.

FRAME;

Tells the screen to refresh.

Next the lines.

for (screenCounter = 0; screenCounter < 5; ++ screenCounter )
{
sprites[screenCounter].n = 129;
FRAME;
}

Steps through each sprite and sets it at 129, which clears the sprite off of the screen.

And that’s all there is to that.

Happy coding.

Advertisements

Author: andydansby

I'm a hobbyist coder working with the ZX Spectrum. Living in New York state near the Syracuse area. I grew up in Virgina. The first computer my parents bought for me was a Timex Sinclair 2068.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s