Calculate Clock Speed (in an emulator)

Discussion in 'C++' started by Shawn B., Feb 22, 2004.

  1. Shawn B.

    Shawn B. Guest

    Greetings,

    I am writing a 65c02 processor simulator. One thing that I do not know how
    to do is emulate clock speed. First, the processor is a 1Mhz CPU that I'm
    attempting to simulate (modern 6502's operate at 14MHz -- unless I'm
    thinking of 65816's).

    In either case, I need to calculate how many cycles to consume per second
    depending on the speed of the simulated processor. I'm at a complete loss
    as to go about "figuring" out how long a cycle should be represented on the
    processor that the program is executing in. What I'm going to do, whether
    this is the way it should be or not, is when each instruction is initially
    decoded, also keep track of when the next instruction can be executed based
    on the number of clock cycles the current instruction requires. This way, I
    can simulate the speed. Anyway, is there a resource or example somewhere of
    how I can determine this? I'm on an x86 processor.


    Thanks,
    Shawn
     
    Shawn B., Feb 22, 2004
    #1
    1. Advertising

  2. "Shawn B." <> wrote...
    > I am writing a 65c02 processor simulator. One thing that I do not know

    how
    > to do is emulate clock speed. First, the processor is a 1Mhz CPU that I'm
    > attempting to simulate (modern 6502's operate at 14MHz -- unless I'm
    > thinking of 65816's).
    >
    > In either case, I need to calculate how many cycles to consume per second
    > depending on the speed of the simulated processor. I'm at a complete loss
    > as to go about "figuring" out how long a cycle should be represented on

    the
    > processor that the program is executing in.


    You are just as any of us would be, there are no means in C++ to "consume"
    any particular number of "cycles per second". The only thing remotely
    related to that is the macro CLOCKS_PER_SEC, which expands into a constant
    expression of type 'clock_t' and designates the number of 'ticks' the
    function 'clock' counts, in one second.

    Without going into hardware specifics and thus using non-standard C++ means
    (if available on your platform) there is no way to do what you want. It
    therefore becomes off-topic.

    > What I'm going to do, whether
    > this is the way it should be or not, is when each instruction is initially
    > decoded, also keep track of when the next instruction can be executed

    based
    > on the number of clock cycles the current instruction requires. This way,

    I
    > can simulate the speed. Anyway, is there a resource or example somewhere

    of
    > how I can determine this? I'm on an x86 processor.


    Try asking in comp.lang.asm.x86 or in a newsgroup for your OS.

    Victor
     
    Victor Bazarov, Feb 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Valentin Tihomirov

    Are clock and divided clock synchronous?

    Valentin Tihomirov, Oct 23, 2003, in forum: VHDL
    Replies:
    11
    Views:
    3,392
    louis lin
    Oct 28, 2003
  2. Replies:
    4
    Views:
    759
    Peter Alfke
    Apr 27, 2006
  3. Replies:
    5
    Views:
    2,260
    Ricardo
    Jun 23, 2006
  4. himassk
    Replies:
    1
    Views:
    1,259
    Paul Uiterlinden
    May 16, 2007
  5. billys13
    Replies:
    3
    Views:
    2,198
    jeppe
    Jun 20, 2008
Loading...

Share This Page