Clockchip and timing

By Accumulator

Champion (333)

Accumulator's picture

21-01-2023, 23:51

How can I measure time an execution takes without using line interrupts.
I have tried several tricks, like using R register, line interrupts and CPL the quantities of mnemonics used on 1 VDP interrupt line, but not using clockchip.
I cannot find any detailed info about using clockchip and reading miliseconds or microseconds.
The only info I could find is port B4, B5 and setting some settings like password, message, but nothing about reading mili or macroseconds.

Measuring speed with line interrupts, which I find quite accurate, tested with 3.57 and 7 mhz.

Is measuring speed by quantity of mnemonics and clockchip possible?

How can I read the mili/macro second of the clockchip? Does it not get screwed up by 7mhz or r800?

Login or register to post comments

By aoineko

Paladin (1002)

aoineko's picture

22-01-2023, 00:18

With the MSX2 Real-time Clock (RP-5C01) you can't get time bellow 1 second. If you are looking for a solution for a development on a real MSX, I don't know a better solution than changing the background color and counting the pixels. ^^

But if you develop on an emulator, I highly recommend you Emulicious which has excellent profling tools that allow you to know the cost of a function to the nearest CPU cycle.

However, Emulicious only emulates MSX 1 and MSX 2.

By Grauw

Ascended (10768)

Grauw's picture

22-01-2023, 03:21

By Accumulator

Champion (333)

Accumulator's picture

22-01-2023, 16:47

Ok, thanks,
The best solution to check R800/Z80 is to check Vertical Retrace bit..

......
                DI
                LD A,2
                OUT (&H99),a
                LD A,15 OR 128
                OUT (&H99),A

                LD HL,0
                LD (RESULT),HL

LINE:        IN A,(&H99)
                AND &h40
                JR Z,LINE

 LINE2:    IN A,(&H99)
               AND &H40
               JR NZ,LINE2
                      
LINE3:      INC HL
                IN A,(&H99)
               AND &H40
               JR Z,LINE3
             
              XOR  A
              OUt (&H99),A
              LD A,15+128
              OUT (&H99),A

             LD (RESULT),HL
             LD A,L
             RRA
             RRA
             RRA
             RRA
             RRA
             RRA
             AND 7
             LD  (CPU),A
             EI
             RET

RESULT: DEFW 0
CPU:      DEFB  0
......

Something like this.

The Higher the amount of HL, The higher the processor speed.
Works on 7Mhz switch, Should be working on R800 as well.
And probably speed between R800 and 7Mhz is also measurable by this way.

In this case the result of HL is much bigger, but more accurate.

When peeking (RESULT), 3.57Mhz and 7Mhz checked on bare hardware and R800 in emulator
Result on 3.57Mhz : &H4x, (RESULT +1 = 4)
Result on 7Mhz : &HCx (RESULT +1 =4)
Result on R800: &H8x (RESULT +1 =5)

OR

peek (CPU)
1: Z80
2: R800
3: 7Mhz

By Arjan

Paladin (787)

Arjan's picture

22-01-2023, 15:32

If you use Visual Studio Code then you can install the extension Z80 Assembly meter. When you select some lines of code, you can see then number of cycles it takes to run that code in the status bar (and the size in bytes too).

By Accumulator

Champion (333)

Accumulator's picture

22-01-2023, 15:48

I just checked the code in OpenMSX.

It detects 3.57 mhz, 7Mhz and R800.
I have a reference book to check cycles and t states.

It is is possible to detect speed modes...

By wouter_

Hero (522)

wouter_'s picture

22-01-2023, 21:05

It is possible to activate the clock chip (RP5C01) test-mode. This will make the clock run 16384x faster. So reading "seconds" then becomes a counter for "61 micro seconds" units.

Though often the RP5C01 is clocked by a separate crystal oscillator (@ 32.768kHz) than the rest of the MSX (typically @ 3.579545MHz). No oscillator is perfect, it's possible that one ticks slightly too fast and/or the other slightly too slow. This means that if you use the clock-chip to measure internal MSX timings, you might see some (slight) variance between different (real) MSX machines.

Another disadvantage is of course that after using this test mode, your MSX clock is no longer set correct.

So indeed, using the VDP as a basis for your time measurements is often a better idea.

By Accumulator

Champion (333)

Accumulator's picture

22-01-2023, 21:44

Another option to measure speed, theoretically is reading clockchip, in normal mode, maybe not even necessary, resetting R register, Looping some code and reading R register again. Putting R in HL, Checking R for 0 and increase H. I have not tested this approach, but in my opinion the faster the processor the faster R increases.

It could be done on processor only. (or am I mistaken?)

I am mistaken!
Just checked, result is same on 7mhz and 3.57... Indeed VDP is the best solution!!