Hi guys, I am guessing some of you know that about a yr ago I launched my Sega Master system emulator (not named yet) project. I wrote the Z80 CPU emulator in Win32ASM using RadASM , there are still some hard to find bugs in it, but many games are running and running well. Just to name a few: Sonic, Sonic 2, Sonic Chaos, Space Harrier, Running Battle, Alien 3, US/EUR BIOS (For some reason the Japanese BIOS freezes).
I hope to have some screenshot writing code up, but I'm just too busy focusing on the stuff more important.

Anyways, I would like to know how much of the x86 CPUs time is being spent in say the Z80 emulator, the VDP emulation and the PSG emulation routines(percentage of the whole applications x86 CPU's time slice), so I have devised a simple algorithm to do this and I would like your input on it.

What I plan to do is either use the Time Stamp Counter or QueryPerformanceCounter.

Basically what I'll do is get the total number of ticks that occur in one second (reading the counter->Sleeping for 1000ms->Sampling counter again and finding difference). Then in my main loop, I do the same for each function that is called (Z80, VDP, PSG), then add the resulting time into an "accumulator" for each component(Z80, VDP, PSG)after 1 second, dividing the number obtained for each component by the numeral obtained in 1 whole second and multiply it by 100 I can get a percentage numeral. Is this a good idea?

I use this approach which is to run x cycles of the Z80 CPU, render scanline, upd PSG the next scanline etc.
Which method I use depends on which is faster (has less overhead, I'm leaning toward RDTSC since it is not a serializing instruction and is only 1 instruction)
Posted on 2004-02-22 21:05:24 by x86asm
Is this how you plan to throttle the emulator?
Posted on 2004-02-22 21:27:26 by bitRAKE
nah, this is how I plan on measuring the amount of time the x86 CPU is spending in certain portions of the time, for example. Might be something like this:

Z80: 12.6%
VDP: 67.4%
PSG: 20.0%

In this case, of my emulators time slice, 12.6% is being spent in the Z80 CPU emulator, 67.4% spent in the VDP emulation routines and 20% spent in the sound (PSG) emulation routines. IF you have used an emulator b4 the earlier versions of the DOS Genecyst had something like this. I plan to use this to see where I should tackle bottlenecks. I did use VC++ profiling, and it does aid to a certain extent, but the major bottleneck can be eradicated easily. I hope this clears everything up :)
Posted on 2004-02-23 20:14:48 by x86asm
I don't know how the percent usage would relate to bottlenecks. The assumption would be that each part of the emulator could be optimized proportionally to the usage - which might not be the case. For example, you might find a neato way to double the speed of PSG, but only a lesser optimization of VDP saving 5%. I don't know about your emu, just blabbering. :) The graphics and sound should more optimizable then the CPU in general.
Posted on 2004-02-23 22:07:50 by bitRAKE