Page 1 of 1

Slowing things down a bit or making a small animation

Posted: Wed Oct 23, 2019 12:31 pm
by Gee-k
Hola.
I've been rewriting a program I made in BASIC and part of it involves changing an arrow (244) to a different one (240) when pressing the relevant key.
The problem I think i'm having is that it's running too quickly. Using BASIC was good as the slowness caused a good animation between the two characters. But now it's running far too quick. In most cases you can't even see it change because it's happening so fast.
When the correct key is pressed (in this case up) the program goes to the following routine, changing the arrow to the new one briefly before jumping to the routine that resets the arrows.

Code: Select all

IncreaseDate:
ld hl,&0a08		;column 10 row 8
call &bb75		;calls firmware to move cursor to hl
call PrintUpArrowPressed	;jump to PrintUpArrowPressed routine
jp ArrowOne		;return arrow to original
If I put in a sub routine to give the CPU something to do in the meantime before resetting the arrows I could see it briefly for a bit longer, but nothing like what I want or have with the BASIC version.

Is there any way I could call on a firmware routine to wait for a moment to let the change be seen and then continue the program?

The routines contain a very small amount of data and the print routine is the same as what is used in one of the z80 tutorial video's
.

Code: Select all

PrintUpArrow:
ld hl,UpArrow
call Print
ret

PrintUpArrowPressed:
ld hl,UpArrowPressed
call Print
ret

Now that i've written this down (this seems t happen a lot), I'm wondering if the next routine that i'm going to put in might slow things down enough to make the effect that i'm after.

Re: Slowing things down a bit or making a small animation

Posted: Thu Oct 24, 2019 11:54 am
by akuyou
one easy way to slow things down is with a HALT - it waits for the next interrupt... just make sure interrupts are on (or it will last forever) eg...

Code: Select all

EI
HALT
If you don't want interrupts to run (eg you're using the firmwares ram, or rom is paged out) A simple pause loop will also work well, so long as you know your program will always run on the same CPU - eg:

Code: Select all

	{code goes here}
		
	ld bc,2000		;delay length
	call PauseBC		;Wait a bit!
	
	{code goes here}

PauseBC:
	dec bc
	ld a,b
	or c
	jr nz,PauseBC
	ret

Re: Slowing things down a bit or making a small animation

Posted: Thu Oct 31, 2019 8:32 pm
by Gee-k
Hey, thanks for the reply! Sorry I didn't say sooner. I've not had much time to look at my coding lately, hopefully get some time tomorrow.
Thanks again!