Writing an emulator in python - implementation questions (for performance)

greg greg at cosc.canterbury.ac.nz
Thu Nov 12 21:29:03 EST 2009


Carl Banks wrote:
> You
> can define constants to access specific registers:
> 
> R1L = 1
> R1H = 2
> R1 = 1
> 
> breg[R1H] = 2
> print wreg[R1]

But keep in mind that named "constants" at the module level
are really global variables, and therefore incur a dictionary
lookup every time they're used.

For maximum speed, nothing beats writing the numeric literals
directly into the code, unfortunately.

Generally, I think you're going to have quite a battle on
your hands to get a pure Python implementation to run as
fast as a real Z80, if it's even possible at all. And if
you do succeed, the code will be pretty awful (due to things
such as not being able to use named constants).

I would be taking a different approach -- develop a prototype
in Python, concentrating on clarity rather than speed, and
later reimplement the core of the emulator as an extension
module, using Pyrex or Cython or otherwise.

-- 
Greg



More information about the Python-list mailing list