Page 1 of 1

Measuring time on CPC more precisely

Posted: Sun Nov 19, 2023 1:05 pm
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 !

Re: Measuring time on CPC more precisely

Posted: Mon Nov 20, 2023 6:33 pm
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-)

Re: Measuring time on CPC more precisely

Posted: Tue Nov 21, 2023 8:57 pm
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 !