Slowing things down a bit or making a small animation

Post programming questions related to the CPC Here!
Post Reply
User avatar
Gee-k
Posts: 28
Joined: Sat May 04, 2019 9:35 am
Location: Scotland
Contact:

Slowing things down a bit or making a small animation

Post by Gee-k » Wed Oct 23, 2019 12:31 pm

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.
You don't fail, You learn how it's not done.
https://www.gee-k.net : Where I blog about my random geeky goings on.

User avatar
akuyou
Posts: 563
Joined: Mon Apr 22, 2019 3:19 am
Contact:

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

Post by akuyou » Thu Oct 24, 2019 11:54 am

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
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

User avatar
Gee-k
Posts: 28
Joined: Sat May 04, 2019 9:35 am
Location: Scotland
Contact:

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

Post by Gee-k » Thu Oct 31, 2019 8:32 pm

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!
You don't fail, You learn how it's not done.
https://www.gee-k.net : Where I blog about my random geeky goings on.

Post Reply

Return to “Amstrad CPC Assembly Programming”