java - Methods of limiting emulated cpu speed -


i'm writing mos 6502 processor emulator part of larger project i've undertaken in spare time. emulator written in java, , before it, know not going efficient , optimized if written in c or assembly, goal make run on various platforms , pulling 2.5mhz on 1ghz processor pretty interpreted emulator. problem quite contrary, need limit number of cycles 1mhz. ive looked around not seen many strategies doing this. ive tried few things including checking time after number of cycles , sleeping difference between expected time , actual time elapsed, checking time slows down emulation factor of 8 have better suggestions or perhaps ways optimize time polling in java reduce slowdown?

the problem using sleep() granularity of 1ms, , actual sleep isn't accurate nearest 1ms depends on rest of system doing. couple of suggestions try (off top of head-- i've not written cpu emulator in java):

  • stick idea, check time between large-ish number of emulated instructions (execution going bit "lumpy" anyway on uniprocessor machine, because os can potentially take away cpu thread several milliseconds @ time);

  • as want execute in order of 1000 emulated instructions per millisecond, try hanging on cpu between "instructions": have program periodically work out trial , error how many runs through loop needs go between instructions "waste" enough cpu make timing work out @ 1 million emulated instructions / sec on average (you may want see if setting thread low priority helps system performance in case).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -