Page 1 of 1

How do one calculate how many scanlines taken to run a routine?

Posted: Mon Jun 17, 2024 12:11 am
by GTR3QQ
:roll:

Welllllllllllllllllllllllllllll..............
This probably no a hard problem to you......... at all...

I just got very confused...

Say you have a routine that eats 3K5 cycles off CPU at 8Mhz, running NTSC 480i,
Knowing little about the Video generation sequence,
I'd think that one second is one second....
So by 3K5/8M you get the proportion used in that one second....
Multiply with the horizontal freq. of NTSC 525x(30) = 15750, should get
(Yeah.... 29.97ish FPS...)

3K5/8000K x 15750 =~ 7lines......


Yet...

I also got this formula.

3500 cycles * 3.125 (dots per cpu tick) / 800 (dots per line)
3.125 being 25 / 8 (Vera clock / Cpu clock)

=~ 14lines..........


so............... heh?

Re: How do one calculate how many scanlines taken to run a routine?

Posted: Mon Jun 17, 2024 2:06 am
by TomXP411
The dot clock is halved in NTSC modes, since the system only generates 262 (or 263) lines per field.

Here's Natt Akuna's video timing chart (from Discord):

VERA Oscillator 25.00000MHz 480p Dot Clock 25.00000MHz (25MHz/1) 240p/480i Dot Clock 12.50000MHz (25MHz/2) L/C Color Clock 3.579545MHz (25MHz*150137/2^20) 480p Line Rate 31.25000kHz (25MHz/800) 240p/480i Line Rate 15.74307kHz (25MHz/(794*2)) 480p Frame Rate 59.523810Hz (25MHz/(525*800)) 480i Frame Rate 29.986805Hz (25MHz/(525*794*2)) 240p Frame Rate 59.859593Hz (25MHz/(263*794*2)) PSG+FIFO Sample Rate 48.82813kHz (25MHz/512) SPI Fast Clock 12.50000MHz (25MHz/2) SPI Slow Clock 390.6250kHz (25MHz/64)

1. Your routine takes 3500 cycles, or 437.5 microseconds.
2. 480i video takes 63 microseconds for one line.
3. 437.5 / 63 = 6.93 lines

Working in dot clocks:
1. The CPU to Dot Clock ratio for 480i is 1.5625
2. 3500 * 1.5625 = 5468 dots
3. One line is 794 dots
4. 5468 / 794 = 6.89

That's within the rounding error.

I think your mistake was that you were trying to use the VGA dot clock with the NTSC video timing.

If you do figure this out for VGA mode, the numbers should be about double:
1. 437.5us / 32us/line = 13.6 lines
2. 3500 cycles * 3.125cycles/dot / 800 dots = 13.67 lines

Re: How do one calculate how many scanlines taken to run a routine?

Posted: Mon Jun 17, 2024 6:51 am
by GTR3QQ
ah. I see. thx!