Sega Master System / Mark III / Game Gear
One method is to count how many scanlines there are, by watching how many values the scanline counter runs through between line 0 and the next line 0. You should get 262 on an NTSC (or Brazilian PAL/M) machine and 313 on a PAL machine.
Unfortunately, this is poorly emulated in many emulators and is not recommended.
An alternative is to simply time (in software) how long a frame takes. A busy loop incrementing a counter can be used so long as the counter doesn't overflow in the time.
The code below is based on World Soccer, with minor modifications to make it generalised. It turns on frame interrupts and disables Z80 interrupts, so the VDP status flags can be used to detect VBlanks. An alternative (but more bulky) method is to use the scanline counter to detect line 0, but this is less reliably emulated.
The main counter loop takes 31 clock cycles per iteration; it should therefore count up to approximately 3579545/60/31 = 1924 on NTSC machines and 3546893/50/31 = 2288 on PAL machines. 2048 is not exactly half-way between these but it probably doesn't matter much.