Measuring time on CPC more precisely

This forum is dedicated to those who wish to suggest new features.
Questo forum è dedicato a chi desidera suggerire nuove feature.
Ce forum est dédié à ceux qui souhaitent suggérer de nouvelles fonctionnalités.
Post Reply
ldir_hector
Posts: 12
Joined: Sun Oct 08, 2023 11:47 am

Measuring time on CPC more precisely

Post by ldir_hector »

With ugBasic you can measure time with TIMER instruction, that gives the the time spend since your computer boot up. The time unit is 1/50 second which is quite precise, but the Amstrad CPC is able to do better !

Thanks to the following code :

Code: Select all

BITMAP ENABLE(320,200,4)
CLS

DECLARE SYSTEM PROC scnkey AT $BB06 ON CPC
DECLARE SYSTEM PROC myTime AT $BD0D ON CPC

DIM de AS WORD
DIM hl AS WORD

PRINT "Attendez un peu, et appuyez sur une touche "
CALL scnkey

ON CPUZ80 BEGIN ASM
	CALL $BD0D
	LD (_de),DE
	LD (_hl),HL
END ASM

DIM time AS FLOAT
time = (de*256.0 + hl)/300.0
PRINT time ; "secondes"
Now you can measure time 6 times more precisely !
spotlessmind1975
Site Admin
Posts: 149
Joined: Fri Oct 06, 2023 8:25 pm

Re: Measuring time on CPC more precisely

Post by spotlessmind1975 »

Hi ldir_hector, wow, that's a very creative way to leverage ugBASIC and measure time! :D
ldir_hector wrote: Sun Nov 19, 2023 1:05 pm The time unit is 1/50 second which is quite precise, but the Amstrad CPC is able to do better !
It almost makes me want to add a "raw" timer, i.e. the possibility of actually reading the real timer of the hardware instead of the PAL/NTSC normalized one. I don't know whether to call it REAL TIMER or RAW TIMER, what do you think?
ldir_hector wrote: Sun Nov 19, 2023 1:05 pm

Code: Select all

DECLARE SYSTEM PROC myTime AT $BD0D ON CPC
Ok, I see that this system call fetches a full 32 bits, and there is no way to declare a system procedure that can pass this value through more than one register, and return a value of 32 bits on more than one register. It's time to add it. 8-)
ldir_hector
Posts: 12
Joined: Sun Oct 08, 2023 11:47 am

Re: Measuring time on CPC more precisely

Post by ldir_hector »

I think that REAL TIMER is confusing, as many would consider that there is a real time clock with the hour stored when the computer stops.
So Raw Timer is better, but I don't know if there is a more precise timer on every computer you support ?

Even worse, from what I understood, the Oric Atmos has no way to synchronize with the VSync ! There is an electronic soldering to do, to be able to do so but it's not standard !
Post Reply