Forum > Games

High precision timing

<< < (2/2)

taazz:

--- Quote from: Rave on March 10, 2018, 03:17:38 pm ---How will I emulate properly a 1.5MHz system properly then?

--- End quote ---
usually with spinwait. You measure the cpu hz and decide on how often you add a delay and how long that delay needs to be. You simple loop through the calculated amount of times to emulate a pause.

Rave:

--- Quote from: taazz on March 10, 2018, 03:36:58 pm ---
--- Quote from: Rave on March 10, 2018, 03:17:38 pm ---How will I emulate properly a 1.5MHz system properly then?

--- End quote ---
usually with spinwait. You measure the cpu hz and decide on how often you add a delay and how long that delay needs to be. You simple loop through the calculated amount of times to emulate a pause.

--- End quote ---

Spinwait? Tell me more, please.


--- Quote from: marcov on March 10, 2018, 03:30:15 pm ---
--- Quote from: Rave on March 10, 2018, 03:17:38 pm ---How will I emulate properly a 1.5MHz system properly then?

--- End quote ---

Time sequences large than 1 instruction, and pause after them to make the timing work.

This will require to identify writes to memory mapped memory hardware (like keyboard/mouse/joystick handling and audio/video) and emulate them, but usually these are known for old systems

--- End quote ---
Well, the latter will be easy since I'm designing all the stuff (the emulator is a part of "fantasy console" with custom cpu, think Pico-8 if it'd use e.g. Notch's DCPU-16), but yeah.

--- Quote from: rvk on March 10, 2018, 03:20:37 pm ---On Windows you can go somewhat more accurate (to 1ms) than TTimer with timeSetEvent() (it's defined in mmsystem).

You also might whip up your own timer in a thread using QueryPerformanceFrequency and QueryPerformanceCounter. Although I'm not sure how accurate you can go (could depend on the cpu) and how cpu-intensive that will be.


--- End quote ---
Thanks, but no. I want to keep it single-threaded if possible and I want something that'd work on every platform.

Ñuño_Martínez:
Hi: I answered your other thread.

Prease DON'T duplicate threads!!!  >:(


--- Quote from: Ñuño_Martínez on March 13, 2018, 01:58:45 pm ---1500000 ticks per second is too much and I doubt you'll find a timer with such precision today.  For example, from the Allegro documentation, you can select microseconds (1000000tps) but most drivers allows milliseconds only (1000tps).  Anyway you can't expect to emulate with such precision in modern systems due to multithread and such.

I recommend you to use another event to time your emulation instead of the clock.  For example, most game and home computer emulators use screen retrace (i.e. frames per second) because in most cases you know how many clock cycles executes in each one and it is a rather low frequency (50fps in Europe, 60fps in USA and Japan, etc).

--- End quote ---

Navigation

[0] Message Index

[*] Previous page

Go to full version